public decimal CalculatePrice(PizzaOrder order)
        {
            decimal actualPrice     = order.Pizzas.Sum(p => p.Price);
            decimal discountedPrice = _discountPoilcy(order);

            return(actualPrice - discountedPrice);
        }
Esempio n. 2
0
        public static decimal BuyOneGetOneFree(PizzaOrder order)
        {
            var pizzas = order.Pizzas;

            if (pizzas.Count < 2)
            {
                return(0m);
            }

            return(pizzas.Min(p => p.Price));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            PizzaOrder order = new PizzaOrder();

            order.Pizzas = new List <Pizza> {
                new Pizza {
                    Size = Size.LARGE, Crust = Crust.STUFFED, Price = 18.25m
                },
                new Pizza {
                    Size = Size.MEDIUM, Crust = Crust.THIN, Price = 18.25m
                }
            };
            PizzaOrderingSystem prepareOrder = new PizzaOrderingSystem(Policies.BuyOneGetOneFree);

            Console.WriteLine(prepareOrder.CalculatePrice(order).ToString());
            Console.Read();
        }
Esempio n. 4
0
 public decimal ComputePolicy(PizzaOrder order)
 {
     return(_discountPoilcies.Max(policy => policy.Invoke(order)));
 }
Esempio n. 5
0
 public static decimal FiveDollarsOffStuffedCrust(PizzaOrder order)
 {
     return(order.Pizzas.Sum(p => p.Crust == Crust.STUFFED ? 5m : 0m));
 }
Esempio n. 6
0
        public static decimal FivePercentOffMoreThanFiftyDollars(PizzaOrder order)
        {
            decimal nonDiscounted = order.Pizzas.Sum(p => p.Price);

            return(nonDiscounted > 50 ? nonDiscounted * 0.05m : 0m);
        }