diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index 045428b..136e142 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -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,