доделала 2 усл!!

This commit is contained in:
kamilia 2024-05-06 03:19:38 +04:00
parent ff37326332
commit e1fa07bcb8

View File

@ -97,7 +97,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
} }
if (count <= 0) if (count <= 0)
{ {
throw new ArgumentException("Кол-во изделий должно быть больше 0", nameof(count)); throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count));
} }
_logger.LogInformation("AddPlaneInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); _logger.LogInformation("AddPlaneInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model); var element = _shopStorage.GetElement(model);
@ -108,6 +108,13 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
} }
_logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id); _logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id);
var countPlanes = element.ShopPlanes.Select(x => x.Value.Item2).Sum();
if (element.MaxPlanes - countPlanes < count)
{
_logger.LogWarning("Shop is overflowed");
return false;
}
if (element.ShopPlanes.TryGetValue(plane.Id, out var pair)) if (element.ShopPlanes.TryGetValue(plane.Id, out var pair))
{ {
element.ShopPlanes[plane.Id] = (plane, count + pair.Item2); element.ShopPlanes[plane.Id] = (plane, count + pair.Item2);
@ -125,7 +132,8 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
Address = element.Address, Address = element.Address,
ShopName = element.ShopName, ShopName = element.ShopName,
DateOpening = element.DateOpening, DateOpening = element.DateOpening,
ShopPlanes = element.ShopPlanes ShopPlanes = element.ShopPlanes,
MaxPlanes = element.MaxPlanes
}); });
return true; return true;
} }