From 81b4335193ca0ba7ef51b018a89f20981742679d Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 17 Apr 2024 01:07:56 +0400 Subject: [PATCH] fix ShopStorage.Sell --- .../Implements/ShopStorage.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/AutoWorkshopFileImplement/Implements/ShopStorage.cs b/AutoWorkshopFileImplement/Implements/ShopStorage.cs index 7c4d816..d6492b1 100644 --- a/AutoWorkshopFileImplement/Implements/ShopStorage.cs +++ b/AutoWorkshopFileImplement/Implements/ShopStorage.cs @@ -87,15 +87,16 @@ namespace AutoWorkshopFileImplement.Implements if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue) return false; - int RemainingSpace = _source.Shops + int TotalRepairsNum = _source.Shops .Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0) .Sum(); - if (RemainingSpace < Model.Count) + if (TotalRepairsNum < Model.Count) return false; var ShopsWithDesiredRepair = _source.Shops .Where(x => x.Repairs.ContainsKey(Model.RepairId.Value)) - .OrderByDescending(x => x.Repairs[Model.RepairId.Value]).ToList(); + .OrderByDescending(x => x.Repairs[Model.RepairId.Value]) + .ToList(); foreach (var Shop in ShopsWithDesiredRepair) { @@ -128,7 +129,13 @@ namespace AutoWorkshopFileImplement.Implements public bool RestockingShops(SupplyBindingModel Model) { - if (Model == null || _source.Shops.Select(x => x.RepairsMaxCount - x.ShopRepairs.Select(y => y.Value.Item2).Sum()).Sum() < Model.Count) + int TotalFreeSpaceNum = _source.Shops + .Select(x => x.RepairsMaxCount - x.ShopRepairs + .Select(y => y.Value.Item2) + .Sum()) + .Sum(); + + if (TotalFreeSpaceNum < Model.Count) return false; foreach (Shop Shop in _source.Shops) @@ -137,7 +144,7 @@ namespace AutoWorkshopFileImplement.Implements if (FreeSpaceNum <= 0) continue; - + FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count); Model.Count -= FreeSpaceNum;