From de6f3af8df37523c020373e5f22dce9b5b06cdf6 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 27 Feb 2023 10:19:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=20=D1=81=20=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=BC=20=D0=B5=D0=B3=D0=BE=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=BA=D1=81=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B8=D0=BC=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index 47dd9df..19c676b 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -82,26 +82,37 @@ namespace LawFirmBusinessLogic.BusinessLogics } _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); - if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument)) + var countDocs = 0; + foreach (var doc in shopElement.ShopDocuments) { - shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count); - _logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + countDocs += doc.Value.Item2; + } + if (shopElement.MaxCountDocuments - countDocs >= count) + { + if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument)) + { + shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count); + _logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + } + else + { + shopElement.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + } + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Adress = shopElement.Adress, + OpeningDate = shopElement.OpeningDate, + ShopDocuments = shopElement.ShopDocuments + }); } else { - shopElement.ShopDocuments[document.Id] = (document, count); - _logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + _logger.LogWarning("Required shop is overflowed"); + return false; } - - _shopStorage.Update(new() - { - Id = shopElement.Id, - Name = shopElement.Name, - Adress = shopElement.Adress, - OpeningDate = shopElement.OpeningDate, - ShopDocuments = shopElement.ShopDocuments - }); - return true; }