public async Task AddExerciseToWorkout(ExerciseAddDto exerciseAddDto, int workoutId) { var exercise = await _exerciseRepo.GetExerciseByNameAsync(exerciseAddDto.Name); var workout = await _workoutRepo.GetWorkoutByIdAsync(workoutId); var workoutExercise = _mapper.Map <WorkoutExercise>(exerciseAddDto); //make a new exercise if it doesnt already exist if (exercise == null) { exercise = new Exercise { Name = exerciseAddDto.Name }; await _exerciseRepo.AddExerciseAsync(exercise); } //add the exercise to the workout workoutExercise.Exercise = exercise; workout.Exercises.Add(workoutExercise); await _unitOfWork.SaveAllAsync(); }
public async Task AddExerciseToWorkoutAsync(AddExerciseRequest exerciseAddDto, int workoutId) { var exercise = await _exerciseRepo.GetExerciseByNameAsync(exerciseAddDto.Name); var workout = await _workoutRepo.GetWorkoutByIdAsync(workoutId); var workoutExercise = _mapper.Map <WorkoutExercise>(exerciseAddDto); //make a new exercise if it doesnt already exist if (exercise == null) { _logger.LogInformation($"Creating a new exercise with the name:{exerciseAddDto.Name}"); exercise = new Exercise { Name = exerciseAddDto.Name }; await _exerciseRepo.AddExerciseAsync(exercise); } //add the exercise to the workout workoutExercise.Exercise = exercise; workout.Exercises.Add(workoutExercise); await _unitOfWork.SaveAllAsync(); }