From 3ac21871a68e929f67da714752d4b79e75ef072b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 9 May 2023 14:35:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/StoreLogic.cs | 7 +++++++ .../StoragesContracts/IStoreStorage.cs | 1 + .../Implements/StoreStorage.cs | 9 +++++++++ .../BlacksmithWorkshopFileImplement/Models/Store.cs | 1 - .../Implements/StoreStorage.cs | 5 +++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs index cdea605..bc06417 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs @@ -6,6 +6,7 @@ using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; using BlacksmithWorkshopDataModels.Models; using Microsoft.Extensions.Logging; +using System.Security.Cryptography.X509Certificates; namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { @@ -109,6 +110,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogWarning("Store with id {Id} not found", model.Id); return false; } + var placeLeft = _storeStorage.GetPlaceLeft(selectedStore); + if (placeLeft < count) + { + _logger.LogWarning("Store with id {Id} can't accomodate {Count} items", model.Id, count); + return false; + } //ищем изделие в магазине if (selectedStore.Manufactures.TryGetValue(manufacture.Id, out var manufactureInStore)) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs index d8502eb..503d958 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs @@ -27,5 +27,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts /// Количество /// bool SellManufacture(IManufactureModel manufacture, int count); + int GetPlaceLeft(IStoreModel store); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs index 192f3ac..4d8b744 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs @@ -113,5 +113,14 @@ namespace BlacksmithWorkshopFileImplement.Implements } return true; } + public int GetPlaceLeft(IStoreModel model) + { + var store = source.Stores.FirstOrDefault(x => x.Id == model.Id); + if (store == null) + { + return 0; + } + return store.MaxManufactures - store.Manufactures.Select(x => x.Value.Item2).Sum(); + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Store.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Store.cs index 4399b77..265d7d1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Store.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Store.cs @@ -76,7 +76,6 @@ namespace BlacksmithWorkshopFileImplement.Models OpeningDate= model.OpeningDate; SavedManufactures = model.Manufactures.ToDictionary(x => x.Value.Item1.Id, x => x.Value.Item2); _manufactures = null; - MaxManufactures = model.MaxManufactures; } public StoreViewModel GetViewModel => new() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs index 1fd4c2e..078650a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs @@ -108,5 +108,10 @@ namespace BlacksmithWorkshopListImplement.Implements { throw new NotImplementedException("Не применяется в данной реализации"); } + + public int GetPlaceLeft(IStoreModel store) + { + throw new NotImplementedException("Не применяется в данной реализации"); + } } } \ No newline at end of file