Beispiel #1
0
        public async Task ResetWorkoutAsync(int workoutId)
        {
            var workout = await _workoutRepo.GetWorkoutByIdAsync(workoutId);

            workout.IsCompleted = false;
            workout.Date        = null;

            foreach (var exercise in workout.Exercises)
            {
                exercise.IsCompleted = false;
            }
            ;
            await _unitOfWork.SaveAllAsync();
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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();
        }