public ActionResult Edit(PizzaViewModel pVM) { try { // TODO: Add update logic here BO.Pizza pizza = FakeDBPizza.Instance.ListePizza.FirstOrDefault(x => x.Id == pVM.pizza.Id); pizza.Nom = pVM.pizza.Nom; pizza.Pate = FakeDBPizza.Instance.ListePates.FirstOrDefault(x => x.Id == pVM.IdPate); pizza.Ingredients = FakeDBPizza.Instance.ListeIngredients.Where(x => pVM.IdIngredients.Contains(x.Id)).ToList(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(PizzaViewModel vm) { try { BO.Pizza pizzaEdited = FakeDb.Instance.ListePizzas.FirstOrDefault(x => x.Id == vm.Pizza.Id); pizzaEdited.Nom = vm.Pizza.Nom; pizzaEdited.Pate = FakeDb.Instance.PatesDisponibles.FirstOrDefault(x => x.Id == vm.IdPate); pizzaEdited.Ingredients = FakeDb.Instance.IngredientsDisponibles.Where( x => vm.IdsIngredients.Contains(x.Id)).ToList(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(PizzaViewModel vm) { try { if (ModelState.IsValid && ValidateVM(vm)) { BO.Pizza pizza = vm.Pizza; pizza.Pate = FakeDb.Instance.PatesDisponibles.FirstOrDefault(x => x.Id == vm.IdPate); pizza.Ingredients = FakeDb.Instance.IngredientsDisponibles.Where( x => vm.IdsIngredients.Contains(x.Id)).ToList(); pizza.Id = FakeDb.Instance.ListePizzas.Count == 0 ? 1 : FakeDb.Instance.ListePizzas.Max(x => x.Id) + 1; FakeDb.Instance.ListePizzas.Add(pizza); return(RedirectToAction("Index")); } else { vm.Pates = FakeDb.Instance.PatesDisponibles.Select( x => new SelectListItem { Text = x.Nom, Value = x.Id.ToString() }).ToList(); vm.Ingredients = FakeDb.Instance.IngredientsDisponibles.Select( x => new SelectListItem { Text = x.Nom, Value = x.Id.ToString() }).ToList(); return(View(vm)); } } catch { vm.Pates = FakeDb.Instance.PatesDisponibles.Select( x => new SelectListItem { Text = x.Nom, Value = x.Id.ToString() }).ToList(); vm.Ingredients = FakeDb.Instance.IngredientsDisponibles.Select( x => new SelectListItem { Text = x.Nom, Value = x.Id.ToString() }).ToList(); return(View(vm)); } }
public ActionResult Delete(int id, FormCollection collection) { BO.Pizza pizzaSupprimee = null; try { pizzaSupprimee = FakeDb.Instance.ListePizzas.FirstOrDefault(x => x.Id == id); if (pizzaSupprimee != null) { FakeDb.Instance.ListePizzas.Remove(pizzaSupprimee); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index")); } } catch { return(View()); } }
// GET: Pizzas/Details/5 public ActionResult Details(int id) { BO.Pizza pizzaSelected = FakeDb.Instance.ListePizzas.FirstOrDefault(x => x.Id == id); return(View(pizzaSelected)); }