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 {