From 119050cef31c96c563239c291e07efb0cb144713 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 22:00:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D1=8F?= =?UTF-8?q?=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.cs | 1 - .../BusinessLogic/ShopLogic.cs | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index a3c9c40..6420d72 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -212,7 +212,6 @@ namespace BlacksmithWorkshop } } - private void AddManufactureToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormAddManufacture)); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs index 2ac74b1..acb9128 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -78,7 +79,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); var shop = _shopStorage.GetElement(model); - if (shop == null) + if (shop == null || !CheckShopCount(shop, count)) { _logger.LogWarning("Add Manufacture operation failed"); @@ -106,6 +107,24 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } + //проверка на переполнение магазина + private bool CheckShopCount(ShopViewModel model, int count) + { + int _countManufactures = 0; + + foreach (var manufacture in model.Manufactures) + { + _countManufactures += model.Manufactures[manufacture.Key].Item2; + } + + if(_countManufactures + count > model.MaxCountManufactures) + { + return false; + } + + return true; + } + public bool Create(ShopBindingModel model) { CheckModel(model);