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

This commit is contained in:
Данияр Аглиуллов 2023-02-20 20:37:47 +04:00
parent 680fd6b501
commit ddd14fe064

View File

@ -133,21 +133,13 @@ namespace ConfectioneryBusinessLogic
} }
_logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id); _logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id);
if (element.Pastries.TryGetValue(pastry.Id, out var pair)) var prevCount = element.Pastries.GetValueOrDefault(pastry.Id, (pastry, 0)).Item2;
{ element.Pastries[pastry.Id] = (pastry, prevCount + count);
element.Pastries[pastry.Id] = (pastry, count + pair.Item2); _logger.LogInformation(
_logger.LogInformation( "AddPastryInShop. Has been added {count} {pastry} in {ShopName}",
"AddPastryInShop. Has been added {count} {pastry} in {ShopName}",
count, pastry.PastryName, element.Name); count, pastry.PastryName, element.Name);
}
else
{
element.Pastries[pastry.Id] = (pastry, count);
_logger.LogInformation(
"AddPastryInShop. Has been added {count} new Pastry {pastry} in {ShopName}",
count, pastry.PastryName, element.Name);
}
_shopStorage.Update(new() _shopStorage.Update(new()
{ {
Id = element.Id, Id = element.Id,