public SaleDiscount SaleDiscount(Burger burger) { var saleDiscount = new SaleDiscount() { SaleDescription = DESCRIPTION }; if (burger == null) { throw new ArgumentNullException("burguer"); } var hasBurgerQtyMultipleOfThree = burger.BurgerIngredients .Any(has => has.Ingredient.IngredientType == IngredientType.Hamburger && has.Qty % 3 == 0); if (hasBurgerQtyMultipleOfThree) { var hamburgerIngredient = burger.BurgerIngredients.FirstOrDefault(has => has.Ingredient.IngredientType == IngredientType.Hamburger); var hamburgerQty = hamburgerIngredient?.Qty; var saleQty = hamburgerQty / DISCOUNT; var qtyDiscount = hamburgerQty - saleQty; saleDiscount.Discount = (qtyDiscount.HasValue ? qtyDiscount.Value : decimal.Zero) * hamburgerIngredient.Ingredient.Price; } return(saleDiscount); }
public SaleDiscount SaleDiscount(Burger burger) { var saleDiscount = new SaleDiscount() { SaleDescription = DESCRIPTION }; if (burger == null) { throw new ArgumentNullException("burguer"); } var hasLettuce = burger.BurgerIngredients.Any(has => has.Ingredient.IngredientType == IngredientType.Lettuce); var hasNotBacon = !burger.BurgerIngredients.Any(has => has.Ingredient.IngredientType == IngredientType.Bacon); if (hasLettuce && hasNotBacon) { saleDiscount.Discount = burger.Price() * DISCOUNT; } return(saleDiscount); }