diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index 42f57b9..0c019ff 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -33,7 +33,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics if (quantity <= 0) { return false; - throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity)); + throw new ArgumentException("Количество добавляемого компьютера должно быть больше 0", nameof(quantity)); } _logger.LogInformation("AddComputerInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); @@ -81,7 +81,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics } if (quantity <= 0) { - throw new ArgumentException("Количество документов должно быть больше 0", nameof(quantity)); + throw new ArgumentException("Количество компьютеров должно быть больше 0", nameof(quantity)); } _logger.LogInformation("AddComputers. ShopName:{ShopName}. Id:{Id}", computer.ComputerName, computer.Id); var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.Computers.Select(x => x.Value.Item2).Sum()).Sum(); diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs index 2251118..8825bad 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs @@ -74,17 +74,13 @@ namespace ComputersShopFileImplement.Implements public bool SellComputers(IComputerModel model, int quantity) { - int hasCount = 0; + int hasCount = source.Shops + .SelectMany(x => x.Computers) + .Where(pair => pair.Key == model.Id) + .Sum(pair => pair.Value.Item2); - source.Shops.ForEach(x => - { - if (x.Computers.TryGetValue(model.Id, out var pair)) - { - hasCount += pair.Item2; - } - }); - - if (hasCount < quantity) return false; + if (hasCount < quantity) + return false; source.Shops.ForEach(x => {