Exemple #1
0
        public async Task <UserProject> AddAsync(UserProjectPostDto entity)
        {
            UserProjectPostDtoValidator validator = new UserProjectPostDtoValidator();
            ValidationResult            results   = validator.Validate(entity);

            if (!results.IsValid)
            {
                throw new ValidationException("UserProjectPostDTO", string.Join(". ", results.Errors));
            }

            var userExists = await userService.GetByIdAsync(entity.UserID);

            if (userExists == null)
            {
                throw new BadRequestException("User not found.");
            }

            var projectExists = await projectService.GetByIdAsync(entity.ProjectID);

            if (projectExists == null)
            {
                throw new BadRequestException("Project not found.");
            }

            var projectRoleExists = await projectRoleService.GetByIdAsync(entity.ProjectRoleID);

            if (projectRoleExists == null)
            {
                throw new BadRequestException("Project role not found.");
            }

            return(await userProjectRepository.AddAsync(mapper.Map <UserProject>(entity)));
        }
        public async Task <IActionResult> GetProjectRoleById(Guid id)
        {
            var projectRole = await projectRoleService.GetByIdAsync(id);

            if (projectRole == null)
            {
                return(NotFound());
            }

            return(Ok(mapper.Map <ProjectRoleResponseDto>(projectRole)));
        }