예제 #1
0
        public IEnumerable <WorkoutExercise> Create(UpdateWorkoutCommand command)
        {
            JsonConverter[] converters       = { new ExerciseSetConverter() };
            var             workoutExercises = JsonConvert.DeserializeObject <IEnumerable <WorkoutExercise> >(command.WorkoutExercises.ToString(), new JsonSerializerSettings()
            {
                Converters = converters
            });

            return(workoutExercises);
        }
예제 #2
0
        public void UpdateWorkout(UpdateWorkoutCommand cmd)
        {
            var workout = _context.WorkoutSummary.Find(cmd.Id);

            if (workout == null)
            {
                throw new Exception("Undable to find the workout");
            }

            cmd.UpdateWorkout(workout);
            _context.SaveChanges();
        }
예제 #3
0
        public void UpdateWorkout(UpdateWorkoutCommand command)
        {
            var workout = this.context.Workouts
                          .Include(p => p.WorkoutExercises)
                          .ThenInclude(p => p.Sets)
                          .SingleOrDefault(p => p.Id == command.WorkoutId);

            if (workout != null)
            {
                workout.WorkoutName      = command.WorkoutName;
                workout.WorkoutExercises = command.WorkoutExercises;
                this.context.Update(workout);
                this.context.SaveChanges();
            }
        }
예제 #4
0
        public async Task <IActionResult> UpdateWorkout([FromBody] JObject jObject)
        {
            var request = JsonConvert.DeserializeObject <UpdateWorkoutRequest>(jObject.ToString());

            var command = new UpdateWorkoutCommand()
            {
                Id               = request.Id,
                WorkoutName      = request.WorkoutName,
                WorkoutExercises = request.WorkoutExercises
            };

            await this.mediator.Send(command);

            return(Ok());
        }
예제 #5
0
 public IActionResult Edit(UpdateWorkoutCommand command)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _service.UpdateWorkout(command);
             return(RedirectToAction(nameof(View), new { id = command.Id }));
         }
     }
     catch (Exception)
     {
         ModelState.AddModelError(
             string.Empty,
             "An error occured saving the workout"
             );
     }
     return(View(command));
 }