From bc6764cb538fcd64c0a733a9ad28d09d9e533aaf Mon Sep 17 00:00:00 2001 From: Salikh Date: Fri, 3 May 2024 15:40:30 +0400 Subject: [PATCH] commit --- .../Implements/ShopStorage .cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs b/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs index aefb9ca..29ae922 100644 --- a/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs +++ b/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs @@ -74,16 +74,13 @@ namespace MotorPlantFileImplement.Implements } return null; } - public bool CheckAvailability(int engineId, int count) - { - int store = _source.Shops.Select(x => x.ShopEngines.Select(y => (y.Value.Item1.Id == engineId ? y.Value.Item2 : 0)).Sum()).Sum(); - return store >= count; - } + public bool SellEngines(IEngineModel model, int count) { - var dres = _source.Engines.FirstOrDefault(x => x.Id == model.Id); + var eng = _source.Engines.FirstOrDefault(x => x.Id == model.Id); + int store = _source.Shops.SelectMany(x => x.ShopEngines).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0); - if (dres == null || !CheckAvailability(model.Id, count)) + if (eng == null || store < count) { return false; } @@ -92,7 +89,7 @@ namespace MotorPlantFileImplement.Implements { var shop = _source.Shops[i]; var engines = shop.ShopEngines; - foreach (var engine in engines.Where(x => x.Value.Item1.Id == dres.Id)) + foreach (var engine in engines.Where(x => x.Value.Item1.Id == eng.Id)) { var selling = Math.Min(engine.Value.Item2, count); engines[engine.Value.Item1.Id] = (engine.Value.Item1, engine.Value.Item2 - selling);