public async Task <ActionResult <Workout> > SaveWorkout([FromBody] WorkoutViewModel workoutViewModel) { Workout entity; if (workoutViewModel.Id == 0) { entity = await _workoutService.CreateNewAsync(); entity.User = await _applicationUserService.GetCurrentUserAsync(User); } else { entity = await _workoutService.GetWorkoutByIdAsync(workoutViewModel.Id); if (entity == null) { return(BadRequest()); } } workoutViewModel.Update(entity); await _workoutService.SaveChangesAsync(); return(Ok(new WorkoutViewModel(entity))); }
//INCOMPLETE public async Task <ActionResult <Workout> > ChangeWorkout([FromBody] WorkoutViewModel workoutViewModel) { Workout entity; entity = await _workoutService.GetWorkoutByIdAsync(workoutViewModel.Id); workoutViewModel.Update(entity); await _workoutService.SaveChangesAsync(); return(Ok(new WorkoutViewModel(entity))); }