diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShopLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShopLogic.cs index e1ab8c0..155c2f0 100644 --- a/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/ShopLogic.cs @@ -126,7 +126,7 @@ namespace ShipyardBusinessLogic.BusinessLogics _logger.LogWarning("AddShip element not found"); return false; } - if (element.Capacity - element.ShopShips.FirstOrDefault(x => x.Key == ship.Id).Value.Item2 < count) + if (element.Capacity - element.ShopShips.Select(x => x.Value.Item2).Sum() < count) { throw new ArgumentNullException("В магазине не хватает места", nameof(count)); } @@ -164,6 +164,12 @@ namespace ShipyardBusinessLogic.BusinessLogics throw new ArgumentException("Количество кораблей должно быть больше 0", nameof(count)); } _logger.LogInformation("AddShips. ShopName:{ShopName}. Id:{Id}", model.ShipName, model.Id); + var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ShopShips.Select(x => x.Value.Item2).Sum()).Sum(); + if (allFreeQuantity < count) + { + _logger.LogWarning("AddTravels operation failed."); + return false; + } foreach (var shop in _shopStorage.GetFullList()) { int freeQuantity = shop.Capacity - shop.ShopShips.Select(x => x.Value.Item2).Sum();