From dc0f2d734699c39ba2a72112eecb772fca8addaa Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Tue, 5 Mar 2024 12:55:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs index 06b9cc4..c43b674 100644 --- a/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs +++ b/IceCreamShop/IceCreamShopListImplement/Implements/ShopStorage.cs @@ -108,21 +108,8 @@ namespace IceCreamShopListImplement.Implements public bool CheckAvailability(int iceCreamId, int count) { - foreach (var shop in _source.Shops) - { - foreach (var icecream in shop.ShopIceCreams) - { - if (icecream.Value.Item1.Id == iceCreamId) - { - count -= icecream.Value.Item2; - } - if (count <= 0) - { - break; - } - } - } - + int minus = _source.Shops.Select(x => x.ShopIceCreams.Select(y => (y.Value.Item1.Id == iceCreamId ? y.Value.Item2 : 0)).Sum()).Sum(); + count -= minus; return count <= 0; }