From 7f02b269a0bd6ec2bab9ddefc18703ae192e2655 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Wed, 28 Feb 2024 17:04:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarRepairShopBusinessLogic/ShopLogic.cs | 41 ++++++++++++++++++- .../StoragesContracts/IShopStorage.cs | 1 - .../Implements/ShopStorage.cs | 31 -------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/CarRepairShop/CarRepairShopBusinessLogic/ShopLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/ShopLogic.cs index d0b7201..877fd07 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/ShopLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/ShopLogic.cs @@ -35,9 +35,46 @@ namespace CarRepairShopBusinessLogic public bool MakeSupply(ShopSearchModel model, IRepairModel repair, int count) { + _logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id); if (model == null) - return false; - return _shopStorage.SupplyRepair(model, repair, count); + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(model)); + } + if (repair == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(repair)); + } + if (count <= 0) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException("Количество должно быть положительным числом"); + } + ShopViewModel curModel = ReadElement(model); + if (curModel == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(curModel)); + } + if (curModel.ShopRepairs.TryGetValue(repair.Id, out var pair)) + { + curModel.ShopRepairs[repair.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopRepairs.Add(repair.Id, (repair, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopRepairs = curModel.ShopRepairs, + }); + _logger.LogInformation("Success. RepairName:{RepairName}. Id:{Id}. Supply:{count}", repair.RepairName, repair.Id, count); + return true; } public ShopViewModel ReadElement(ShopSearchModel model) diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IShopStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IShopStorage.cs index 91a81fc..18d5e95 100644 --- a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IShopStorage.cs +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IShopStorage.cs @@ -13,6 +13,5 @@ namespace CarRepairShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool SupplyRepair(ShopSearchModel model, IRepairModel repair, int Count); } } diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/ShopStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/ShopStorage.cs index 825579a..470eba9 100644 --- a/CarRepairShop/CarRepairShopListImplement/Implements/ShopStorage.cs +++ b/CarRepairShop/CarRepairShopListImplement/Implements/ShopStorage.cs @@ -100,36 +100,5 @@ namespace CarRepairShopListImplement.Implements } return null; } - - public bool SupplyRepair(ShopSearchModel model, IRepairModel repair, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (repair == null) - throw new ArgumentNullException(nameof(repair)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - ShopViewModel curModel = GetElement(model); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopRepairs.TryGetValue(repair.Id, out var pair)) - { - curModel.ShopRepairs[repair.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopRepairs.Add(repair.Id, (repair, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopRepairs = curModel.ShopRepairs, - }); - return true; - } } }