From 5afff36beef3c4a58f7b591f2a31323fe6587641 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 24 Mar 2023 00:35:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ShopLogic.cs | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs index acb9128..2985011 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs @@ -79,13 +79,18 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); var shop = _shopStorage.GetElement(model); - if (shop == null || !CheckShopCount(shop, count)) + if (shop == null) { _logger.LogWarning("Add Manufacture operation failed"); return false; } + if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count)); + } + if (!shop.Manufactures.ContainsKey(manufacture.Id)) { shop.Manufactures[manufacture.Id] = (manufacture, count); @@ -107,24 +112,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } - //проверка на переполнение магазина - private bool CheckShopCount(ShopViewModel model, int count) - { - int _countManufactures = 0; - - foreach (var manufacture in model.Manufactures) - { - _countManufactures += model.Manufactures[manufacture.Key].Item2; - } - - if(_countManufactures + count > model.MaxCountManufactures) - { - return false; - } - - return true; - } - public bool Create(ShopBindingModel model) { CheckModel(model);