From 0e8c49cbe4382334596dbaa96f73d5f8d6425417 Mon Sep 17 00:00:00 2001 From: K Date: Fri, 3 May 2024 00:58:13 +0300 Subject: [PATCH] lab1hard --- .../BusinessLogic/ShopLogic.cs | 20 ++++++++++--------- .../BusinessLogicsContracts/IShopLogic.cs | 2 +- .../FormShopRefill.cs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 35ddc6b..1e2707b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -88,8 +88,8 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics } return true; } - - public bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) + //логика пополнения магазина + public bool RefillShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) { if (shopModel == null) { @@ -103,25 +103,27 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics { throw new ArgumentException("В магазине должен быть хотя бы один товар", nameof(count)); } - _logger.LogInformation("ReplenishShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + _logger.LogInformation("RefillShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) { - _logger.LogWarning("ReplenishShop(GetElement). Element not found"); + _logger.LogWarning("RefillShop(GetElement). Element not found"); return false; } - if (shop.ShopReinforceds.ContainsKey(reinforced.Id)) + if (shop.ShopReinforceds.ContainsKey(reinforced.Id))//если есть товар то плюс { var shopR = shop.ShopReinforceds[reinforced.Id]; shopR.Item2 += count; shop.ShopReinforceds[reinforced.Id] = shopR; - _logger.LogInformation("ReplenishShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + _logger.LogInformation("RefillShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, shop.ShopName); } - else + else//если нет то просто добавляем { shop.ShopReinforceds.Add(reinforced.Id, (reinforced, count)); - _logger.LogInformation("ReplenishShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + _logger.LogInformation("RefillShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, shop.ShopName); } if (_shopStorage.Update(new ShopBindingModel() @@ -133,7 +135,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics ShopReinforceds = shop.ShopReinforceds, }) == null) { - _logger.LogWarning("ReplenishShop. Update operation failed"); + _logger.LogWarning("RefillShop. Update operation failed"); return false; } return true; diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index 624250e..156fa96 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -22,6 +22,6 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); + bool RefillShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs index fd340ab..c272b61 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs @@ -95,7 +95,7 @@ namespace PrecastConcretePlantView { throw new Exception("Изделие не найдено."); } - var operationResult = _logicShop.ReplenishShop(new ShopSearchModel + var operationResult = _logicShop.RefillShop(new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },