Пример #1
0
        //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));
        }
Пример #2
0
        //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);
            }
        }
Пример #3
0
        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));
        }