ПИбд-23 Насыров Артур Газинурович Лабораторная работа №2 #3
@ -42,8 +42,32 @@ namespace FlowerShopBusinessLogic
|
||||
public bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count)
|
||||
{
|
||||
if (model == null)
|
||||
return false;
|
||||
return SupplyFlowers(model, flower, count);
|
||||
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;
|
||||
}
|
||||
|
||||
public ShopViewModel ReadElement(ShopSearchModel model)
|
||||
@ -131,36 +155,5 @@ namespace FlowerShopBusinessLogic
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,5 @@ namespace FlowerShopContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
//bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int Count);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user