commit
This commit is contained in:
parent
1cb89e24d7
commit
6456ec0dbf
@ -74,16 +74,13 @@ namespace MotorPlantFileImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
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)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -92,7 +89,7 @@ namespace MotorPlantFileImplement.Implements
|
|||||||
{
|
{
|
||||||
var shop = _source.Shops[i];
|
var shop = _source.Shops[i];
|
||||||
var engines = shop.ShopEngines;
|
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);
|
var selling = Math.Min(engine.Value.Item2, count);
|
||||||
engines[engine.Value.Item1.Id] = (engine.Value.Item1, engine.Value.Item2 - selling);
|
engines[engine.Value.Item1.Id] = (engine.Value.Item1, engine.Value.Item2 - selling);
|
||||||
|
Loading…
Reference in New Issue
Block a user