Compare commits

..

3 Commits

Author SHA1 Message Date
e934dc229f Merge branch 'LabWork02Hard' into LabWork03Hard 2023-03-14 12:44:17 +04:00
ad9256c5a6 Тру 2023-03-14 02:21:39 +04:00
48552db0b2 Исправление ошибок прошлого 2023-03-14 02:19:41 +04:00

View File

@ -171,27 +171,35 @@ 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, temp))
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
{
_logger.LogWarning("При добавлении суши в магазины произошла ошибка");
_logger.LogWarning("AddSushiInShop operation failed.");
return false;
}
count -= temp;
count -= countFree;
}
else
{
if (!AddSushiInShop(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddSushiInShop operation failed.");
return false;
}
count = 0;
}
if (count == 0)
{
return true;