отрефакторен метод пополнения магазина
This commit is contained in:
commit
302bb6a100
@ -140,24 +140,13 @@ namespace ConfectioneryBusinessLogic
|
|||||||
}
|
}
|
||||||
_logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id);
|
_logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id);
|
||||||
|
|
||||||
var currentCountPasties = element.Pastries.Select(x => x.Value.Item2).Sum();
|
|
||||||
if (currentCountPasties + count > element.MaxCountPastries)
|
var prevCount = element.Pastries.GetValueOrDefault(pastry.Id, (pastry, 0)).Item2;
|
||||||
{
|
element.Pastries[pastry.Id] = (pastry, prevCount + count);
|
||||||
_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);
|
|
||||||
}
|
|
||||||
_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);
|
||||||
|
|
||||||
_shopStorage.Update(new()
|
_shopStorage.Update(new()
|
||||||
{
|
{
|
||||||
Id = element.Id,
|
Id = element.Id,
|
||||||
|
Loading…
Reference in New Issue
Block a user