Ejemplo n.º 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();
        }
Ejemplo 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
            });
        }