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; - } } }