From 0f24ed319f961b79e41f55b164b4045be88c29ec Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Fri, 1 Mar 2024 22:42:42 +0400 Subject: [PATCH] freee tato --- FlowerShopBusinessLogic/ShopLogic.cs | 59 ++++++++----------- .../StoragesContracts/IShopStorage.cs | 1 - 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/FlowerShopBusinessLogic/ShopLogic.cs b/FlowerShopBusinessLogic/ShopLogic.cs index e22e00b..9e064d1 100644 --- a/FlowerShopBusinessLogic/ShopLogic.cs +++ b/FlowerShopBusinessLogic/ShopLogic.cs @@ -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; - } } } diff --git a/FlowerShopContracts/StoragesContracts/IShopStorage.cs b/FlowerShopContracts/StoragesContracts/IShopStorage.cs index 122a79f..671f8c8 100644 --- a/FlowerShopContracts/StoragesContracts/IShopStorage.cs +++ b/FlowerShopContracts/StoragesContracts/IShopStorage.cs @@ -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); } }