diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index 920f493..cf9663c 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -115,6 +115,10 @@ namespace ConfectioneryBusinessLogic { throw new ArgumentNullException(nameof(model)); } + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + } _logger.LogInformation("AddPastryInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); @@ -125,7 +129,22 @@ namespace ConfectioneryBusinessLogic } _logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id); - return element.Pastries.TryAdd(pastry.Id, (pastry, count)); + + if (element.Pastries.TryGetValue(pastry.Id, out var pair)) + { + pair.Item2 += count; + _logger.LogInformation( + "AddPastryInShop. Has been added {count} {pastry} in {ShopName}", + 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); + } + return true; } } }