//GET: MealPlan/Edit public ActionResult Edit(int id) { var service = CreateMealPlanService(); var detail = service.GetMealPlanById(id); var model = new MealPlanEdit { MealPlanId = detail.MealPlanId, Title = detail.Title, Length = detail.Length }; return(View(model)); }
//EDIT MEALPLAN BY ID public bool UpdateMealPlan(MealPlanEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .MealPlans .SingleOrDefault(m => m.MealPlanId == model.MealPlanId && m.OwnerId == _userId); entity.Title = model.Title; entity.Length = model.Length; entity.DateModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, MealPlanEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.MealPlanId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateMealPlanService(); if (service.UpdateMealPlan(model)) { TempData["SaveResult"] = "Your Meal Plan was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Meal Plan could not be updated"); return(View(model)); }