// GET: Dish/Edit/5 public ActionResult Edit(int id) { DishViewModel dvm = new DishViewModel(); dvm.Dish = facade.GetDishGateway().Get(id); dvm.Dish.Ingredients.ForEach(x => dvm.SelectedIds.Add(x.Id)); return View(dvm); }
public ActionResult Create(DishViewModel dvm) { try { List<Ingredient> temp = new List<Ingredient>(); foreach (var item in dvm.SelectedIds) { temp.Add(facade.GetIngredientGateway().Get(item)); } Dish dish = dvm.Dish; dish.Ingredients = temp; facade.GetDishGateway().Add(dish); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, DishViewModel dvm) { try { Dish dish = dvm.Dish; dvm.SelectedIds.ForEach(x => dish.Ingredients.Add(facade.GetIngredientGateway().Get(x))); facade.GetDishGateway().Update(id, dish); return RedirectToAction("Index"); } catch { return View(); } }
// GET: Dish/Create public ActionResult Create() { DishViewModel dvm = new DishViewModel(); return View(dvm); }