//GET : WorkoutPlan/Edit public ActionResult Edit(int id) { var service = CreateWorkoutPlanService(); var detail = service.GetWorkoutById(id); var model = new WorkoutPlanUpdate() { WorkoutPlanId = detail.WorkoutPlanId, Title = detail.Title }; return(View(model)); }
//EDIT WORKOUT PLAN BY ID public bool UpdateWorkoutPlan(WorkoutPlanUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .WorkoutPlans .SingleOrDefault(w => w.WorkoutPlanId == model.WorkoutPlanId && w.OwnerId == _userId); entity.Title = model.Title; entity.DateModifiedUtc = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, WorkoutPlanUpdate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWorkoutPlanService(); if (service.UpdateWorkoutPlan(model)) { TempData["SaveResult"] = "Workout Plan successfully updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Unable to edit Workout Plan"); return(View(model)); }