Ejemplo n.º 1
0
        public IActionResult Put(int exerciseId, [FromBody] ExerciseEditDto exerciseEditDto)
        {
            exerciseEditDto.Id = exerciseId;
            exerciseEditDto.UserId = int.Parse(User.FindFirst(ClaimTypes.Name).Value);

            var validationResult = _exerciseEditDtoValidator.Validate(exerciseEditDto);

            if (!validationResult.IsValid)
                return BadRequest(ValidationHelpers.ConvertValidationResult(validationResult));

            var exercise = _exerciseRepository.EditExercise(exerciseId, exerciseEditDto);
            return Ok(exercise);
        }
Ejemplo n.º 2
0
        public IActionResult Get(int exerciseId)
        {
            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId = int.Parse(userIdString);

            var exerciseGetDto = new ExerciseGetDto { Id = exerciseId, UserId = userId };
            var validationResult = _exerciseGetDtoValidator.Validate(exerciseGetDto);

            if (!validationResult.IsValid)
                return BadRequest(ValidationHelpers.ConvertValidationResult(validationResult));

            var exercise = _exerciseRepository.GetExercise(exerciseId);
            return Ok(exercise);
        }
Ejemplo n.º 3
0
        public IActionResult Post([FromBody] ExerciseCreateDto exerciseCreateDto)
        {
            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId = int.Parse(userIdString);

            exerciseCreateDto.UserId = userId;

            var validationResult = _exerciseCreateDtoValidator.Validate(exerciseCreateDto);

            if (!validationResult.IsValid)
                return BadRequest(ValidationHelpers.ConvertValidationResult(validationResult));

            var exercise = _exerciseRepository.CreateExercise(exerciseCreateDto);
            return Created($"api/exercise/{exercise.Id}", exercise);
        }
Ejemplo n.º 4
0
        public IActionResult Put(int equipmentId, [FromBody] EquipmentEditDto equipmentEditDto)
        {
            equipmentEditDto.Id     = equipmentId;
            equipmentEditDto.UserId = int.Parse(User.FindFirst(ClaimTypes.Name).Value);

            var validationResult = _equipmentEditDtoValidator.Validate(equipmentEditDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            var routine = _equipmentRepository.EditEquipment(equipmentId, equipmentEditDto);

            return(Ok(routine));
        }
        public IActionResult Put(int routineId, [FromBody] RoutineEditDto routineEditDto)
        {
            routineEditDto.Id     = routineId;
            routineEditDto.UserId = int.Parse(User.FindFirst(ClaimTypes.Name).Value);

            var validationResult = _routineEditDtoValidator.Validate(routineEditDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            var routine = _routineRepository.EditRoutine(routineId, routineEditDto);

            return(Ok(routine));
        }
Ejemplo n.º 6
0
        public IActionResult Delete(int exerciseId)
        {
            ExerciseDeleteDto exerciseDeleteDto = new ExerciseDeleteDto { Id = exerciseId };

            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId = int.Parse(userIdString);

            exerciseDeleteDto.UserId = userId;

            var validationResult = _exerciseDeleteDtoValidator.Validate(exerciseDeleteDto);

            if (!validationResult.IsValid)
                return BadRequest(ValidationHelpers.ConvertValidationResult(validationResult));

            _exerciseRepository.DeleteExercise(exerciseId);
            return Ok();
        }
        public IActionResult Post(RoutineCreateDto routineCreateDto)
        {
            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId       = int.Parse(userIdString);

            routineCreateDto.UserId = userId;

            var validationResult = _routineCreateDtoValidator.Validate(routineCreateDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            var routine = _routineRepository.CreateRoutine(routineCreateDto);

            return(Created($"api/routine/{routine.Id}", routine));
        }
Ejemplo n.º 8
0
        public IActionResult Post([FromBody] EquipmentCreateDto equipmentCreateDto)
        {
            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId       = int.Parse(userIdString);

            equipmentCreateDto.UserId = userId;

            var validationResult = _equipmentCreateDtoValidator.Validate(equipmentCreateDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            var equipment = _equipmentRepository.CreateEquipment(equipmentCreateDto);

            return(Created("[controller]", equipment));
        }
        public IActionResult Get(int routineId)
        {
            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId       = int.Parse(userIdString);

            var routineGetDto = new RoutineGetDto {
                Id = routineId, UserId = userId
            };
            var validationResult = _routineGetDtoValidator.Validate(routineGetDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            var routine = _routineRepository.GetRoutine(routineId);

            return(Ok(routine));
        }
Ejemplo n.º 10
0
        public IActionResult Get(int equipmentId)
        {
            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId       = int.Parse(userIdString);

            var equipmentGetDto = new EquipmentGetDto {
                Id = equipmentId, UserId = userId
            };
            var validationResult = _equipmentGetDtoValidator.Validate(equipmentGetDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            var equipment = _equipmentRepository.GetEquipment(equipmentId);

            return(Ok(equipment));
        }
Ejemplo n.º 11
0
        public IActionResult Delete(int routineId)
        {
            RoutineDeleteDto routineDeleteDto = new RoutineDeleteDto {
                Id = routineId
            };

            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId       = int.Parse(userIdString);

            routineDeleteDto.UserId = userId;

            var validationResult = _routineDeleteDtoValidator.Validate(routineDeleteDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            _routineRepository.DeleteRoutine(routineId);
            return(Ok());
        }
Ejemplo n.º 12
0
        public IActionResult Delete(int equipmentId)
        {
            EquipmentDeleteDto equipmentDeleteDto = new EquipmentDeleteDto {
                Id = equipmentId
            };

            var userIdString = User.FindFirst(ClaimTypes.Name)?.Value;
            var userId       = int.Parse(userIdString);

            equipmentDeleteDto.UserId = userId;

            var validationResult = _equipmentDeleteDtoValidator.Validate(equipmentDeleteDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(ValidationHelpers.ConvertValidationResult(validationResult)));
            }

            _equipmentRepository.DeleteEquipment(equipmentId);
            return(Ok());
        }