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