From a6c28cd37ec812468639d7d7a834bfc81dcb9ad1 Mon Sep 17 00:00:00 2001 From: pgirl111 Date: Mon, 13 Feb 2023 10:37:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20(=D0=BD=D0=BE=20=D0=BD=D1=83=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=B8=D1=82?= =?UTF-8?q?=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/FormMain.cs | 10 ++----- .../FurnitureAssembly/FormShop.cs | 1 - .../ShopLogic.cs | 28 ++++++++++++++++--- .../StoragesContracts/IShopStorage.cs | 3 +- .../Implements/ShopStorage.cs | 13 --------- .../Models/Shop.cs | 17 +---------- 6 files changed, 28 insertions(+), 44 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index cc422a4..09e1bb0 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -195,18 +195,12 @@ namespace FurnitureAssembly var modelShop = new ShopBindingModel { - Id = form.Id, - ShopName = form.ShopModel.ShopName, - Address = form.ShopModel.Address, - DateOpening = form.ShopModel.DateOpening, + Id = form.Id }; var modelFurn = new FurnitureBindingModel { - Id = form.FurnitureId, - FurnitureName = form.FurnitureModel.FurnitureName, - Price = form.FurnitureModel.Price, - FurnitureComponents = form.FurnitureModel.FurnitureComponents + Id = form.FurnitureId }; var operationResult = _shopLogic.AddFurniture(modelShop, modelFurn, form.Count); diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.cs b/FurnitureAssembly/FurnitureAssembly/FormShop.cs index b49158b..5063508 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormShop.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.cs @@ -96,7 +96,6 @@ namespace FurnitureAssembly dateTimePicker.Value = view.DateOpening; _shopFurnitures = view.Furnitures ?? new Dictionary(); - dta LoadData(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs index 544b405..41094d8 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs @@ -16,11 +16,13 @@ namespace FurnitureAssemblyBusinessLogic { private readonly ILogger _logger; private readonly IShopStorage _shopStorage; + private readonly IFurnitureStorage _furnitureStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage) + public ShopLogic(ILogger logger, IShopStorage shopStorage, IFurnitureStorage furnitureStorage) { _logger = logger; _shopStorage = shopStorage; + _furnitureStorage = furnitureStorage; } public ShopViewModel? ReadElement(ShopSearchModel model) { @@ -117,9 +119,27 @@ namespace FurnitureAssemblyBusinessLogic public bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count) { - CheckModel(model); - - if (_shopStorage.AddFurniture(model, furnitureModel, count) == null) + var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.Id }); + var furniture = _furnitureStorage.GetElement(new FurnitureSearchModel { Id = furnitureModel.Id }); + + if (shop == null || furniture == null) + { + return false; + } + if (shop.Furnitures.ContainsKey(furniture.Id)) + { + int prev_count = shop.Furnitures[furniture.Id].Item2; + shop.Furnitures[furniture.Id] = (furniture, prev_count + count); + } + else + { + shop.Furnitures[furniture.Id] = (furniture, count); + } + model.Furnitures = shop.Furnitures; + model.DateOpening = shop.DateOpening; + model.Address = shop.Address; + model.ShopName = shop.ShopName; + if (_shopStorage.Update(model) == null) { _logger.LogWarning("Replenishment operation failed"); return false; diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs index a72939f..cc4fa6a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs @@ -12,7 +12,6 @@ namespace FurnitureAssemblyContracts.StoragesContracts ShopViewModel? GetElement(ShopSearchModel model); ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); - ShopViewModel? Delete(ShopBindingModel model); - ShopViewModel? AddFurniture(ShopBindingModel model, FurnitureBindingModel furniture, int count); + ShopViewModel? Delete(ShopBindingModel model); } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs index 3b1731a..65e0e2b 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs @@ -109,18 +109,5 @@ namespace FurnitureAssemblyListImplement.Implements } return null; } - - public ShopViewModel? AddFurniture(ShopBindingModel model, FurnitureBindingModel furniture, int count) - { - foreach (var shop in _source.Shops) - { - if (shop.Id == model.Id) - { - shop.AddFurniture(model, furniture, count); - return shop.GetViewModel; - } - } - return null; - } } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs index 780811a..4b64a67 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs @@ -48,22 +48,7 @@ namespace FurnitureAssemblyListImplement.Models DateOpening = model.DateOpening; Furnitures = model.Furnitures; } - - public void AddFurniture(ShopBindingModel? model, FurnitureBindingModel furniture, int count) - { - if (model == null) - { - return; - } - if (Furnitures.ContainsKey(furniture.Id)) - { - int prev_count = Furnitures[furniture.Id].Item2; - Furnitures[furniture.Id] = (furniture, prev_count + count); - } else - { - Furnitures[furniture.Id] = (furniture, count); - } - } + public ShopViewModel GetViewModel => new() { Id = Id,