public decimal getLowestTotal() { if (!AvailableSpecials.Any()) { LowestTotal = Total; return(LowestTotal); } foreach (var item in AvailableSpecials) { var node = new TrolleyTotal() { RemainProduct = RemainProduct.ToDictionary(t => t.Key, t => new Product { Name = t.Value.Name, Price = t.Value.Price, Quantity = t.Value.Quantity }), UsedSpecials = new List <Special>(UsedSpecials) }; node.UsedSpecials.Add(item); foreach (var productItem in item.Quantities) { node.RemainProduct[productItem.Name].Quantity -= productItem.Quantity; } node.Total = node.CalTotal(); node.AvailableSpecials = node.GetValidSpecial(AvailableSpecials); Children.Add(node); } foreach (var child in Children) { child.getLowestTotal(); if (Total > child.LowestTotal) { LowestTotal = child.LowestTotal; } } return(LowestTotal); }
public List <Special> GetValidSpecial(List <Special> specials) { return(specials.Where(x => x.Quantities.All(quantity => RemainProduct.ContainsKey(quantity.Name) && RemainProduct[quantity.Name].Quantity >= quantity.Quantity)).ToList()); }