This commit is contained in:
Павел Сорокин 2023-03-19 18:16:59 +04:00
parent 18423dca74
commit 6867c80ec0

View File

@ -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();