From 48552db0b2351e814ff23285b3c4f5cbf5f70f75 Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 9 Mar 2023 13:13:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D1=88=D0=BB=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index 13761bc..d9d86c3 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -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)