public static Pizza Map(Data.Pizzas otherPizza) => new Pizza { Size = otherPizza.SizeId, Price = (decimal)otherPizza.Price, CrustType = otherPizza.PizzaIngredientJunction.First(i => i.Ingredient.Type.Equals("crust")).Ingredient.Name, SauceType = otherPizza.PizzaIngredientJunction.First(i => i.Ingredient.Type.Equals("sauce")).Ingredient.Name, Toppings = otherPizza.PizzaIngredientJunction.Where(i => i.Ingredient.Type.Equals("topping")).Select(j => j.Ingredient.Name).ToHashSet() };
public static Pizza Map(Data.Pizzas pizza) => new Pizza { PizzaID = pizza.PizzaId, OrderID = pizza.OrderId, Sauce = pizza.Sauce, Crust = pizza.Crust, Size = pizza.Size, Price = pizza.Price, Pepperoni = pizza.Pepperoni, Bacon = pizza.Bacon, Chicken = pizza.Chicken, Sausage = pizza.Sausage, Onions = pizza.Onions, Olives = pizza.Olives };
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(); } }
public void AddPizza(Data.Pizzas p) { _db.Add(p); }