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); }
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(); }
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(); } }
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()); }
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)); }