Compare commits
3 Commits
50e45e7fb3
...
e934dc229f
Author | SHA1 | Date | |
---|---|---|---|
e934dc229f | |||
ad9256c5a6 | |||
48552db0b2 |
@ -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, 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;
|
||||
|
Loading…
Reference in New Issue
Block a user