Исправление ошибок прошлого

This commit is contained in:
dasha 2023-03-09 13:13:48 +04:00
parent 75e4c71d5d
commit 48552db0b2

View File

@ -171,33 +171,42 @@ namespace SushiBarBusinessLogic.BusinessLogics
{
throw new ArgumentException("Количество суши должно быть больше 0", nameof(count));
}
var freePlaces = _shopStorage.GetFullList()
var freeCount = _shopStorage.GetFullList()
.Select(x => x.MaxCountSushi - x.ListSushi
.Select(p => p.Value.Item2).Sum()).Sum() - count;
if (freePlaces < 0)
if (freeCount < 0)
{
_logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
var temp = Math.Min(count, shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum());
if (temp <= 0)
int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum();
if (countFree < count)
{
continue;
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
{
_logger.LogWarning("AddSushiInShop operation failed.");
return false;
}
count -= countFree;
}
if (!AddSushiInShop(new() { Id = shop.Id }, model, temp))
else
{
_logger.LogWarning("При добавлении суши в магазины произошла ошибка");
return false;
if (!AddSushiInShop(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddSushiInShop operation failed.");
return false;
}
count = 0;
}
count -= temp;
if (count == 0)
{
return true;
}
}
return true;
_logger.LogWarning("AddSushi operation failed.");
return false;
}
public bool SellSushi(ISushiModel model, int count)