lab3-hard-to-lab4-hard #8

Closed
Salikh wants to merge 14 commits from lab3-hard into laba4-hard
Showing only changes of commit 6456ec0dbf - Show all commits

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