示例#1
0
        public void AddOrder(Order order)
        {
            //take care of order basics
            _db.Add(Mapper.Map(order));
            //take care of individual pizzas
            foreach (var p in order.Pizzas)
            {
                Data.Pizzas datP = Mapper.Map(p);
                _db.Add(datP);
                Save();
                OrderPizzaJunction opj = new OrderPizzaJunction {
                    OrderId = order.Id, Quantity = 1, PizzaId = datP.Id
                };
                AddOrderPizzaJunction(opj);
                //add crust to ingredients
                Data.Ingredients datI = Mapper.Map(new Ingredient {
                    Name = p.CrustType, Type = "crust"
                });
                AddPizzaIngredientJunction(new PizzaIngredientJunction {
                    PizzaId = datP.Id, IngredientId = datI.Name
                });
                //add sauce to ingredients
                datI = Mapper.Map(new Ingredient {
                    Name = p.SauceType, Type = "sauce"
                });
                AddPizzaIngredientJunction(new PizzaIngredientJunction {
                    PizzaId = datP.Id, IngredientId = datI.Name
                });

                //add remaining toppings to ingredients
                foreach (var t in p.Toppings)
                {
                    datI = Mapper.Map(new Ingredient {
                        Name = t, Type = "topping"
                    });
                    AddPizzaIngredientJunction(new PizzaIngredientJunction {
                        PizzaId = datP.Id, IngredientId = datI.Name
                    });
                }
                Save();
            }
        }
示例#2
0
 public void AddOrderPizzaJunction(OrderPizzaJunction opj)
 {
     _db.Add(opj);
 }