internal static Models.Pizza Map(IPizza pizza) { if (pizza == null) { return(null); } var p = new Models.Pizza() { CrustId = pizza.Crust.Id, Price = pizza.Price, Size = pizza.Size.Id, }; foreach (var topping in (from topping in pizza.Toppings select topping.Id).Distinct()) { p.PizzaToppings.Add(new PizzaToppings() { Amount = (byte)(from t in pizza.Toppings where t.Id == topping select t).Count(), ToppingId = topping, }); } return(p); }
internal static IPizza Map(Domain.Models.Pizza pizza) { if (pizza == null) { return(null); } return(new CompletedPizza() { Crust = PizzaMapper.Map(pizza.Crust), Price = pizza.Price, Size = PizzaMapper.Map(pizza.SizeNavigation), Toppings = new List <Topping>((from topping in pizza.PizzaToppings select Map(topping.Topping))) }); }
internal static IPizza Map(Domain.Models.Pizza pizza) { if (pizza == null) { return(null); } List <Topping> toppings = new List <Topping>(); foreach (var t in pizza.PizzaToppings) { Topping topp = Map(t.Topping); for (int i = 0; i < t.Amount; i++) { toppings.Add(topp); } } return(new CompletedPizza() { Crust = PizzaMapper.Map(pizza.Crust), Price = pizza.Price, Size = PizzaMapper.Map(pizza.SizeNavigation), Toppings = toppings }); }