отрефакторен метод пополнения магазина

This commit is contained in:
Данияр Аглиуллов 2023-02-20 20:39:16 +04:00
commit 302bb6a100

View File

@ -140,24 +140,13 @@ namespace ConfectioneryBusinessLogic
}
_logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id);
var currentCountPasties = element.Pastries.Select(x => x.Value.Item2).Sum();
if (currentCountPasties + count > element.MaxCountPastries)
{
_logger.LogWarning("AddPastryInShop. The number of pastry {count} exceeds maximum {max}",
currentCountPasties + count, element.MaxCountPastries);
return false;
}
if (element.Pastries.TryGetValue(pastry.Id, out var pair))
{
element.Pastries[pastry.Id] = (pastry, count + pair.Item2);
}
else
{
element.Pastries[pastry.Id] = (pastry, count);
}
var prevCount = element.Pastries.GetValueOrDefault(pastry.Id, (pastry, 0)).Item2;
element.Pastries[pastry.Id] = (pastry, prevCount + count);
_logger.LogInformation(
"AddPastryInShop. Has been added {count} {pastry} in {ShopName}",
count, pastry.PastryName, element.Name);
_shopStorage.Update(new()
{
Id = element.Id,