示例#1
0
        public async Task <int> AddAsync(string name, string partOfBody)
        {
            var exercise = await _exerciseRepository.CheckIfExistsAsync(name);

            exercise = new Exercise(name, PartOfBody.GetPart(partOfBody));

            await _exerciseRepository.AddAsync(exercise);

            return(exercise.Id);
        }
        public async Task <ExerciseDto> AddAsync(ExerciseDto exercise)
        {
            var registeredExercise = await repository.GetByAsync(u => u.Name == exercise.Name);

            if (registeredExercise != null)
            {
                throw new ValueAlreadyRegisteredException(exercise.Name);
            }

            registeredExercise = await repository.AddAsync(exercise.ToEntity <Exercise>(Mapper));

            return(registeredExercise.ToDto <ExerciseDto>(Mapper));
        }
示例#3
0
        public async Task <ExerciseResponse> SaveAsync(Excercise excercise)
        {
            try
            {
                await _exerciseRepository.AddAsync(excercise);

                await _unitOfWork.CompleteAsync();

                return(new ExerciseResponse(excercise));
            }
            catch (Exception e)
            {
                return(new ExerciseResponse($"An error occured when saving the exercise: {e.Message}"));
            }
        }
示例#4
0
        public async Task <IList <ExerciseDTO> > AddExerciseToWorkoutAsync(ExerciseDTO exerciseDTO)
        {
            var existentExercises = await _exerciseRepository.GetByWorkoutIdAsync(exerciseDTO.WorkoutId);

            var order = -1;

            if (existentExercises.Count > 0)
            {
                order = existentExercises.Select(x => x.Order).LastOrDefault();
            }

            var exerciseToAdd = new Exercise {
                Order = ++order, ExerciseTemplateId = exerciseDTO.ExerciseTemplateId, WorkoutId = exerciseDTO.WorkoutId
            };

            await _exerciseRepository.AddAsync(exerciseToAdd);

            return(await GetExercisesFromWorkoutAsync(exerciseDTO.WorkoutId));
        }
示例#5
0
        public async Task <Exercise> GetOrCreateExerciseAsync(ExerciseDto exerciseDto)
        {
            var chapter = await _chapterService.GetOrCreateChapterAsync(exerciseDto.CourseCode, exerciseDto.ChapterNumber);

            Exercise exercise;

            try
            {
                exercise = await _exerciseRepository.GetSingleAsync(chapter.Id, exerciseDto.ExerciseCode);
            }
            catch (DataNotFoundException)
            {
                exercise = new Exercise
                {
                    ChapterId = chapter.Id,
                    Code      = exerciseDto.ExerciseCode
                };
                exercise = await _exerciseRepository.AddAsync(exercise);
            }

            return(exercise);
        }