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> AddNewUserProject([FromBody] UserProjectPostDto userProjectPostDto) { var userProjectResp = await userProjectService.AddAsync(userProjectPostDto); return(CreatedAtAction("GetClient", new { userId = userProjectResp.UserID, projectId = userProjectResp.ProjectID }, mapper.Map <UserProjectResponseDto>(userProjectResp))); }