Упрощение проверки при продаже изделий

This commit is contained in:
Илья 2024-03-11 23:00:37 +04:00
parent 69123995cd
commit d7ecf984f1

View File

@ -88,8 +88,7 @@ namespace IceCreamShopFileImplement.Implements
public bool MakeSale(IIceCreamModel model, int count) public bool MakeSale(IIceCreamModel model, int count)
{ {
var iceCream = source.IceCreams.FirstOrDefault(x => x.Id == model.Id); var iceCream = source.IceCreams.FirstOrDefault(x => x.Id == model.Id);
int countInShops = source.Shops.Select(x => x.ShopIceCreams.Any(y => y.Key == model.Id) int countInShops = source.Shops.SelectMany(x => x.ShopIceCreams).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0);
? x.ShopIceCreams.Where(y => y.Key == model.Id).First().Value.Item2 : 0).Sum();
if (iceCream == null || countInShops < count) if (iceCream == null || countInShops < count)
{ {