示例#1
0
        public static void Main(string[] args)
        {
#if debug
            IPizza bp  = BasicPizza.TakeOrder(4, 2);
            var    bpc = bp.TotalCost();
            if (bp != null)
            {
                bp = new TomatoSaucePizza(bp);
                var tsc = bp.TotalCost();
                bp = new MozarellaCheesePizza(bp);
                var mcc = bp.TotalCost();
                bp = new HamPizza(bp);
                var hc = bp.TotalCost();
            }
#endif

#if debug
            using (var scope = host.Services.CreateScope())
                using (var context = scope.ServiceProvider.GetService <AppDbContext>())
                {
                    try
                    {
                        DBInitializer.Initialize(context);
                        context.Database.EnsureCreated();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
#endif
            var host = BuildWebHost(args);
            host.Run();
        }
示例#2
0
        public static void Main(string[] args)
        {
            Pizza largePizza = new LargePizza();

            largePizza = new HamPizza(largePizza);
            largePizza = new CheesePizza(largePizza);

            Console.WriteLine("{0} costs {1}.", largePizza.GetDescription(), largePizza.CalculateCost());

            Console.ReadKey();
        }
示例#3
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
            });
        }
        public Pizza CreatePizza(PizzaType pizzaType)
        {
            Pizza pizza = null;

            if (pizzaType == PizzaType.Cheese)
            {
                pizza = new CheesePizza();
            }
            else if (pizzaType == PizzaType.Funghi)
            {
                pizza = new FunghiPizza();
            }
            else if (pizzaType == PizzaType.Ham)
            {
                pizza = new HamPizza();
            }
            return(pizza);
        }
            public Pizza CreatePizza(PizzaType type)
            {
                Pizza pizza = null;

                switch (type)
                {
                case PizzaType.Cheese:
                    pizza = new CheseePizza();
                    break;

                case PizzaType.Ham:
                    pizza = new HamPizza();
                    break;

                default:
                    break;
                }
                return(pizza);
            }