public static IOrderable CreatePizza(string type)
        {
            IOrderable chosenPizza;

            switch (type)
            {
            case "1":
                chosenPizza = new Margerita();
                return(chosenPizza);

            case "2":
                chosenPizza = new Hawaii();
                return(chosenPizza);

            case "3":
                chosenPizza = new KebabPizza();
                return(chosenPizza);

            case "4":
                chosenPizza = new QuatroStagioni();
                return(chosenPizza);

            default:
                throw new NotSupportedException();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Uses the new order request model to calculate the cost for each pizza and
        /// their toppings with the distance for delivery as total cost factor.
        /// </summary>
        /// <param name="order">Represents a pizza order request</param>
        /// <returns>A price for the order, description of the order, order ID, total pizzas
        /// and the delivery cost.</returns>
        public static OrderVm GetPriceQuoteForCustomerOrder(NewOrderVm order)
        {
            IPizza appliedTopping = BasicPizza.TakeOrder(order.CustomPizzas.Count, order.Distance);

            if (appliedTopping == null)
            {
                return(new OrderVm());
            }

            List <string> itemDescriptions = new List <string>();

            foreach (var cp in order.CustomPizzas)
            {
                string desc = cp.Toppings.Count > 0 ? "Yummy crust pizza with" : "Yummy crust pizza";

                foreach (string topping in cp.Toppings)
                {
                    switch (topping.ToUpper())
                    {
                    case "TOMATOSAUCE":
                        appliedTopping = new TomatoSaucePizza(appliedTopping);
                        desc          += appliedTopping.GetDescription();
                        break;

                    case "MOZARELLACHEESE":
                        appliedTopping = new MozarellaCheesePizza(appliedTopping);
                        desc          += appliedTopping.GetDescription();
                        break;

                    case "HAM":
                        appliedTopping = new HamPizza(appliedTopping);
                        desc          += appliedTopping.GetDescription();
                        break;

                    case "KEBAB":
                        appliedTopping = new KebabPizza(appliedTopping);
                        desc          += appliedTopping.GetDescription();
                        break;

                    default:
                        break;
                    }
                }

                itemDescriptions.Add(desc);
            }

            return(new OrderVm()
            {
                TotalCost = Math.Round(appliedTopping.TotalCost(), 2),
                TotalPizzas = order.CustomPizzas.Count,
                OrderedItems = itemDescriptions
            });
        }