public IActionResult AddPizza(PizzaViewModel pizza) { // Pizza Choice (types) pizza.Presets = pizzaViewModel.Presets; pizza.Sizes = pizzaViewModel.Sizes; pizza.Crusts = pizzaViewModel.Crusts; pizza.Toppings = pizzaViewModel.Toppings; // remove ModelState.Remove("Crust"); ModelState.Remove("SelectedToppings"); if (ModelState.IsValid) { if (pizza.PizzaName == "Custom") // This will create Crust and Toppings, if custom { return(View("CustomizePizza", pizza)); } // option for preset pizza.Crust = pizzaViewModel.Presets.Find(x => x.Name == pizza.PizzaName).Crust.Name; pizza.SelectedToppings = pizzaViewModel.Presets.Find(x => x.Name == pizza.PizzaName).Toppings.Select(x => x.Name).ToList(); orderViewModel.AddPizza(pizza, TempData.Peek("CustomerLoggedIn").ToString()); return(Redirect("/Order/Home")); } return(View("AddPizza", pizza)); // form was not filled out correctly }
public IActionResult PlaceOrder(PizzaViewModel pizzaViewModel) { var crust = _db.Crusts.FirstOrDefault(c => c.Name == pizzaViewModel.Crust); var size = _db.Sizes.FirstOrDefault(s => s.Name == pizzaViewModel.Size); List <ToppingModel> toppings = new List <ToppingModel>(); foreach (var topping in pizzaViewModel.SelectedToppings) { var top = _db.Toppings.FirstOrDefault(t => t.Name == topping); toppings.Add(top); } PizzaFactory pf = new PizzaFactory(); var pizza = pf.Create() as PizzaModel; var newPizza = pf.Update(pizza, crust, size, toppings) as PizzaModel; OrderViewModel orderViewModel = new OrderViewModel(); orderViewModel.AddPizza(newPizza); return(View("ShowOrder", orderViewModel)); }