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));
|
throw new ArgumentException("Количество суши должно быть больше 0", nameof(count));
|
||||||
}
|
}
|
||||||
var freeCount = _shopStorage.GetFullList()
|
var freePlaces = _shopStorage.GetFullList()
|
||||||
.Select(x => x.MaxCountSushi - x.ListSushi
|
.Select(x => x.MaxCountSushi - x.ListSushi
|
||||||
.Select(p => p.Value.Item2).Sum()).Sum() - count;
|
.Select(p => p.Value.Item2).Sum()).Sum() - count;
|
||||||
if (freeCount < 0)
|
if (freePlaces < 0)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены.");
|
_logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach (var shop in _shopStorage.GetFullList())
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
{
|
{
|
||||||
int countFree = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum();
|
var temp = Math.Min(count, shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum());
|
||||||
if (countFree < count)
|
if (temp <= 0)
|
||||||
{
|
{
|
||||||
if (!AddSushiInShop(new() { Id = shop.Id }, model, countFree))
|
continue;
|
||||||
{
|
|
||||||
_logger.LogWarning("AddSushiInShop operation failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
count -= countFree;
|
|
||||||
}
|
}
|
||||||
else
|
if (!AddSushiInShop(new() { Id = shop.Id }, model, temp))
|
||||||
{
|
{
|
||||||
if (!AddSushiInShop(new() { Id = shop.Id }, model, count))
|
_logger.LogWarning("При добавлении суши в магазины произошла ошибка");
|
||||||
{
|
return false;
|
||||||
_logger.LogWarning("AddSushiInShop operation failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
}
|
}
|
||||||
|
count -= temp;
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user