This commit is contained in:
Salikh 2024-05-03 15:40:30 +04:00
parent 7772cc65d2
commit bc6764cb53

View File

@ -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);