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; }