Новая проверка.

This commit is contained in:
Programmist73 2023-03-24 00:35:13 +04:00
parent 119050cef3
commit 5afff36bee

View File

@ -79,13 +79,18 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
_logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
var shop = _shopStorage.GetElement(model);
if (shop == null || !CheckShopCount(shop, count))
if (shop == null)
{
_logger.LogWarning("Add Manufacture operation failed");
return false;
}
if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count)
{
throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count));
}
if (!shop.Manufactures.ContainsKey(manufacture.Id))
{
shop.Manufactures[manufacture.Id] = (manufacture, count);
@ -107,24 +112,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
return true;
}
//проверка на переполнение магазина
private bool CheckShopCount(ShopViewModel model, int count)
{
int _countManufactures = 0;
foreach (var manufacture in model.Manufactures)
{
_countManufactures += model.Manufactures[manufacture.Key].Item2;
}
if(_countManufactures + count > model.MaxCountManufactures)
{
return false;
}
return true;
}
public bool Create(ShopBindingModel model)
{
CheckModel(model);