Compare commits
No commits in common. "e934dc229f92f0e15d39f2ffd5c383e7e8ceb38a" and "50e45e7fb39201244c8888cd7609b90fdae85ca4" have entirely different histories.
e934dc229f
...
50e45e7fb3
@ -171,35 +171,27 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentException("Количество суши должно быть больше 0", nameof(count));
|
||||
}
|
||||
var freeCount = _shopStorage.GetFullList()
|
||||
var freePlaces = _shopStorage.GetFullList()
|
||||
.Select(x => x.MaxCountSushi - x.ListSushi
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - count;
|
||||
if (freeCount < 0)
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены.");
|
||||
return false;
|
||||
}
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum();
|
||||
if (countFree < count)
|
||||
var temp = Math.Min(count, shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum());
|
||||
if (temp <= 0)
|
||||
{
|
||||
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
|
||||
{
|
||||
_logger.LogWarning("AddSushiInShop operation failed.");
|
||||
return false;
|
||||
}
|
||||
count -= countFree;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
if (!AddSushiInShop(new() { Id = shop.Id }, model, temp))
|
||||
{
|
||||
if (!AddSushiInShop(new() { Id = shop.Id }, model, count))
|
||||
{
|
||||
_logger.LogWarning("AddSushiInShop operation failed.");
|
||||
return false;
|
||||
}
|
||||
count = 0;
|
||||
_logger.LogWarning("При добавлении суши в магазины произошла ошибка");
|
||||
return false;
|
||||
}
|
||||
count -= temp;
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user