private static (decimal total, List <BasketItem> basket) PairedBuy(string sku1, string sku2, decimal discountedPrice, List <BasketItem> basket) { bool ShouldApplyPromotion(List <BasketItem> basket) { return(basket.Exists(bi => bi.Sku == sku1 && bi.Quantity >= 1) && basket.Exists(bi => bi.Sku == sku2 && bi.Quantity >= 1)); } var total = 0M; while (ShouldApplyPromotion(basket)) { basket = basket .Select(bi => Promotions.ReduceQuantityForSku(bi, sku1, 1)) .Select(bi => Promotions.ReduceQuantityForSku(bi, sku2, 1)) .Where(bi => bi.Quantity > 0).ToList(); total += discountedPrice; } return(total, basket); }
public CalculatePromotion(Promotions promotions) { _promotions = promotions; }