diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index 6d92da1..37b155d 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -40,9 +40,46 @@ namespace ComputersShopBusinessLogic.BusinessLogics public bool MakeSupply(ShopSearchModel model, IComputerModel Computer, int count) { + _logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id); if (model == null) - return false; - return _shopStorage.SupplyComputer(model, Computer, count); + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(model)); + } + if (Computer == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(Computer)); + } + 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.ShopComputers.TryGetValue(Computer.Id, out var pair)) + { + curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopComputers.Add(Computer.Id, (Computer, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopComputers = curModel.ShopComputers, + }); + _logger.LogInformation("Success. ComputerName:{ComputerName}. Id:{Id}. Supply:{count}", Computer.ComputerName, Computer.Id, count); + return true; } public ShopViewModel ReadElement(ShopSearchModel model) diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs index 2627905..28a54dc 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs @@ -18,6 +18,5 @@ namespace ComputersShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool SupplyComputer(ShopSearchModel model, IComputerModel computer, int Count); } } diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs index c3d6b48..2af4d05 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -104,36 +104,5 @@ namespace ComputersShopListImplement.Implements } return null; } - - public bool SupplyComputer(ShopSearchModel model, IComputerModel Computer, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (Computer == null) - throw new ArgumentNullException(nameof(Computer)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - ShopViewModel curModel = GetElement(model); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair)) - { - curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopComputers.Add(Computer.Id, (Computer, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopComputers = curModel.ShopComputers, - }); - return true; - } } }