Mochalov D.V. LabWork05_Hard #13

Closed
b0n3l3sS wants to merge 63 commits from LabWork05_Hard into LabWork05_Base
Showing only changes of commit de6f3af8df - Show all commits

View File

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