public void CreatePresetPizza(string name, int orderId)
        {
            PresetPizzaModel preset = _db.PresetPizzas
                                      .Where(p => p.Name == name)
                                      .Include(p => p.Crust)
                                      .Include(p => p.Size)
                                      .Include(p => p.PresetToppings).ThenInclude(pt => pt.Topping)
                                      .SingleOrDefault();

            PizzaModel pizza = new PizzaModel()
            {
                Crust = preset.Crust,
                Size  = preset.Size,
                Order = _db.Orders.SingleOrDefault(o => o.Id == orderId),
                Name  = preset.Name
            };

            foreach (var pt in preset.PresetToppings)
            {
                PizzaToppingModel pizzaTopping = new PizzaToppingModel()
                {
                    Pizza   = pizza,
                    Topping = pt.Topping
                };
                _db.PizzaToppings.Add(pizzaTopping);
                _db.SaveChanges();
            }
        }
示例#2
0
        public decimal ViewPrice(PresetPizzaModel pizza)
        {
            decimal price = 0.00m;

            price += (pizza.Crust.Price + pizza.Size.Price);
            foreach (var pt in pizza.PresetToppings)
            {
                price += pt.Topping.Price;
            }

            return(price);
        }
        public decimal ReadNewPrice(string name, int orderId)
        {
            decimal price = 0.00m;

            OrderModel order = _db.Orders
                               .Where(o => o.Id == orderId)
                               .Include(o => o.Pizzas).ThenInclude(p => p.Size)
                               .Include(o => o.Pizzas).ThenInclude(p => p.Crust)
                               .Include(o => o.Pizzas).ThenInclude(p => p.PizzaToppings).ThenInclude(pt => pt.Topping)
                               .SingleOrDefault();

            PresetPizzaModel presetPizza = _db.PresetPizzas
                                           .Where(p => p.Name == name)
                                           .Include(p => p.Size)
                                           .Include(p => p.Crust)
                                           .Include(p => p.PresetToppings).ThenInclude(pt => pt.Topping)
                                           .SingleOrDefault();

            //Get the price of the current order
            foreach (var p in order.Pizzas.ToList())
            {
                price += (p.Size.Price + p.Crust.Price);
                foreach (var pt in p.PizzaToppings)
                {
                    price += pt.Topping.Price;
                }
            }

            //Add the price of the pizza to add
            price += (presetPizza.Size.Price + presetPizza.Crust.Price);
            foreach (var pt in presetPizza.PresetToppings)
            {
                price += pt.Topping.Price;
            }

            return(price);
        }