public async Task <ProjectUserDto> CreateProjectUserAsync(ProjectUserDto projectUser) { UserEntity userEntity = await _userStorage.FindAsync(u => u.Id == projectUser.UserId); if (userEntity == null) { throw new ProjectUserException(ExceptionMessage.InvalidUserId); } ProjectEntity project = await _projectStorage.FindAsync(p => p.Id == projectUser.ProjectId); ProjectUserEntity projectUserEntity = _mapper.Map <ProjectUserEntity>(projectUser); // if there are currently no members on the project, // default first member to project owner projectUserEntity.IsOwner = project.ProjectUsers.Count == 0; // Remove user if project collaborator exist await _projectCollaboratorSuggestionStorage.DeleteAllAsync(pcs => pcs.ProjectId == projectUser.ProjectId && pcs.UserId == projectUser.UserId); var createdProjectUser = await _projectUserStorage.CreateAsync(projectUserEntity); var createdProjectUserDto = _mapper.Map <ProjectUserDto>(createdProjectUser); createdProjectUserDto.Username = userEntity.Username; var projectDto = _mapper.Map <ProjectDto>(project); var notificationDto = new NotificationDto(createdProjectUserDto.UserId) { NotificationObject = projectDto }; await _notifier.SendYouJoinedProjectNotificationAsync(notificationDto); return(createdProjectUserDto); }
protected virtual async Task <string> AddUserToProject(TEntity project) { ProjectUserEntity entity = CreateProjectUser(User.UserId); TEntity updatedProject = await Projects.UpdateAsync( p => p.Id == project.Id && !p.Users.Any(pu => pu.UserRef == User.UserId), update => update.Add(p => p.Users, entity)); return(updatedProject != null ? entity.Id : null); }
private async Task CheckCanUpdateDeleteAsync(string id) { if (SystemRole == SystemRoles.User) { ProjectUserEntity projectUser = await Projects.Query().SelectMany(p => p.Users) .SingleOrDefaultAsync(u => u.Id == id); if (projectUser.UserRef != UserId) { throw ForbiddenException(); } } }
private bool IsUserProjectAdmin(TEntity project) { // Is the user part of the project ProjectUserEntity projectUser = project.Users.FirstOrDefault(u => u.UserRef == User.UserId); if (projectUser != null) { if (projectUser.Role == ProjectAdminRole) { return(true); } } return(false); }
async Task <ProjectUserResource> IResourceMapper <ProjectUserResource, ProjectUserEntity> .MapAsync( IEnumerable <string> included, Dictionary <string, IResource> resources, ProjectUserEntity entity) { return(await MapAsync(included, resources, (TEntity)entity)); }