Esempio n. 1
0
        //Edit Workout
        public bool UpdateWorkout(WorkoutUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Workouts
                    .SingleOrDefault(w => w.WorkoutId == model.WorkoutId && w.OwnerId == _userId);

                entity.Title = model.Title;

                return(ctx.SaveChanges() == 1);
            }
        }
        // GET : Workout/Edit
        public ActionResult Edit(int id)
        {
            var service = CreateWorkoutService();
            var detail  = service.GetWorkoutById(id);

            var model =
                new WorkoutUpdate()
            {
                WorkoutId = detail.WorkoutId,
                Title     = detail.Title
            };

            return(View(model));
        }
        public ActionResult Edit(int id, WorkoutUpdate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateWorkoutService();

            if (service.UpdateWorkout(model))
            {
                TempData["SaveResult"] = "Workout updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Could not update model");
            return(View(model));
        }