Подменил ShopStorage в FileImplements
This commit is contained in:
parent
211ce494ba
commit
61650ce283
@ -75,5 +75,58 @@ namespace SecuritySystemFileImplement.Implements
|
|||||||
source.SaveShops();
|
source.SaveShops();
|
||||||
return shop.GetViewModel;
|
return shop.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SellSecures(ISecureModel secureModel, int securesCount)
|
||||||
|
{
|
||||||
|
var car = source.Secures.FirstOrDefault(x => x.Id == secureModel.Id);
|
||||||
|
|
||||||
|
if (car == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == car.Id));
|
||||||
|
|
||||||
|
int countStore = 0;
|
||||||
|
|
||||||
|
foreach (var it in shopSecures)
|
||||||
|
countStore += it.Value.Item2;
|
||||||
|
|
||||||
|
if (securesCount > countStore)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach (var shop in source.Shops)
|
||||||
|
{
|
||||||
|
var cars = shop.ShopSecures;
|
||||||
|
|
||||||
|
foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id))
|
||||||
|
{
|
||||||
|
int min = Math.Min(c.Value.Item2, securesCount);
|
||||||
|
cars[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||||
|
securesCount -= min;
|
||||||
|
|
||||||
|
if (securesCount <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
Name = shop.Name,
|
||||||
|
Address = shop.Address,
|
||||||
|
MaxSecuresCount = shop.MaxSecuresCount,
|
||||||
|
OpeningDate = shop.OpeningDate,
|
||||||
|
ShopSecures = cars
|
||||||
|
});
|
||||||
|
|
||||||
|
source.SaveShops();
|
||||||
|
|
||||||
|
if (securesCount <= 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user