freee tato

This commit is contained in:
antoc0der 2024-03-01 22:42:42 +04:00
parent 66a55b2d90
commit 0f24ed319f
2 changed files with 26 additions and 34 deletions

View File

@ -42,8 +42,32 @@ namespace FlowerShopBusinessLogic
public bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count) public bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count)
{ {
if (model == null) if (model == null)
return false; throw new ArgumentNullException(nameof(model));
return SupplyFlowers(model, flower, count); if (flower == null)
throw new ArgumentNullException(nameof(flower));
if (count <= 0)
throw new ArgumentNullException("Количество должно быть положительным числом");
var curModel = _shopStorage.GetElement(model);
if (curModel == null)
throw new ArgumentNullException(nameof(curModel));
if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair))
{
curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count);
}
else
{
curModel.ShopFlowers.Add(flower.Id, (flower, count));
}
Update(new()
{
Id = curModel.Id,
ShopName = curModel.ShopName,
DateOpen = curModel.DateOpen,
Address = curModel.Address,
ShopFlowers = curModel.ShopFlowers,
});
return true;
} }
public ShopViewModel ReadElement(ShopSearchModel model) public ShopViewModel ReadElement(ShopSearchModel model)
@ -131,36 +155,5 @@ namespace FlowerShopBusinessLogic
throw new InvalidOperationException("Магазин с таким названием уже есть"); throw new InvalidOperationException("Магазин с таким названием уже есть");
} }
} }
public bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int count)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (flower == null)
throw new ArgumentNullException(nameof(flower));
if (count <= 0)
throw new ArgumentNullException("Количество должно быть положительным числом");
var curModel = _shopStorage.GetElement(model);
if (curModel == null)
throw new ArgumentNullException(nameof(curModel));
if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair))
{
curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count);
}
else
{
curModel.ShopFlowers.Add(flower.Id, (flower, count));
}
Update(new()
{
Id = curModel.Id,
ShopName = curModel.ShopName,
DateOpen = curModel.DateOpen,
Address = curModel.Address,
ShopFlowers = curModel.ShopFlowers,
});
return true;
}
} }
} }

View File

@ -18,6 +18,5 @@ namespace FlowerShopContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model);
//bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int Count);
} }
} }