private async Task <IActionResult> AddExerciseStepAsync(string userId, string targetId, string serieId, IExerciseStepDto exercise, IExerciseStepApplicationService service)
        {
            if (!string.Equals(User.Identity.Name, userId))
            {
                return(Forbid());
            }

            try
            {
                var registeredExercise = await service.AddAsync(userId, targetId, serieId, exercise);

                return(CreatedAtRoute(nameof(GetExerciseStepByIdAsync), new { userId, targetId, serieId, id = registeredExercise.Id }, registeredExercise));
            }
            catch (Application.Exceptions.ApplicationException ex)
            {
                return(BadRequest(ex.ToResult()));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(new { reason = ex.Message }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(Problem("Something is not right, calm down calm down! We're working to fix...(I hope so!"));
            }
        }
Esempio n. 2
0
 public static IExerciseStep ToEntity(this IExerciseStepDto dto, IMapper mapper)
 => dto is SingleExerciseStepDto?mapper.Map <SingleExerciseStep>(dto) :
     dto is ConjugateExerciseStepDto ? (IExerciseStep)mapper.Map <ConjugateExerciseStep>(dto) :
     dto is DropSetExerciseStepDto?mapper.Map <DropSetExerciseStep>(dto) :
Esempio n. 3
0
        public async Task <IExerciseStepDto> AddAsync(string userId, string targetId, string serieId, IExerciseStepDto exercise)
        {
            var user = await repository.GetByAsync(u => u.Id == userId);

            var target    = user.Targets.FirstOrDefault(t => t.Id == targetId);
            var userSerie = target.Series.FirstOrDefault(s => s.Id == serieId);

            var exerciseToUpdate = exercise.ToEntity(Mapper);

            exerciseToUpdate.Id = repository.GenerateId();

            userSerie.Steps.Add(exerciseToUpdate);

            await repository.UpdateAsync(user);

            return(exerciseToUpdate.ToDto(Mapper));
        }