From 62162888ec49abd0f9a4c29b679eaec2a4e03614 Mon Sep 17 00:00:00 2001 From: goldfest Date: Thu, 2 May 2024 23:54:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ShopLogic.cs | 11 +++++++---- .../Controllers/ShopController.cs | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ShopLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ShopLogic.cs index 56cfe73..bcb069f 100644 --- a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ShopLogic.cs @@ -107,6 +107,13 @@ namespace TravelCompanyBusinessLogic.BusinessLogics { throw new ArgumentException("Магазина не существует"); } + + var totalSupplyCount = shop.ShopTravels.Values.Sum(supply => supply.Item2) + model.Count; + if (totalSupplyCount > shop.TravelMaxCount) + { + throw new ArgumentException("Количество поставляемых товаров превышает максимальное количество товаров, которое может содержать магазин"); + } + if (shop.ShopTravels.ContainsKey(model.TravelId)) { var oldValue = shop.ShopTravels[model.TravelId]; @@ -123,10 +130,6 @@ namespace TravelCompanyBusinessLogic.BusinessLogics { throw new ArgumentException($"Поставка: Товар с id:{model.TravelId} не найденн"); } - if (shop.ShopTravels.Sum(kv => kv.Value.Item2) + model.Count > shop.TravelMaxCount) - { - throw new ArgumentException("Превышена максимальная вместимость магазина"); - } shop.ShopTravels.Add(model.TravelId, (Travel, model.Count)); } diff --git a/TravelCompany/TravelCompanyRestApi/Controllers/ShopController.cs b/TravelCompany/TravelCompanyRestApi/Controllers/ShopController.cs index 67b59c3..ec35292 100644 --- a/TravelCompany/TravelCompanyRestApi/Controllers/ShopController.cs +++ b/TravelCompany/TravelCompanyRestApi/Controllers/ShopController.cs @@ -3,6 +3,7 @@ using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.BusinessLogicsContracts; using TravelCompanyContracts.SearchModels; using TravelCompanyContracts.ViewModels; +using System.Net.Http; namespace TravelCompanyRestApi.Controllers {