Exemple #1
0
        public async Task <ServiceResult <MemberModel> > AddMember(NewMemberModel model, string userId)
        {
            var project = await _dbContext.Projects
                          .FirstOrDefaultAsync(p => p.Id == model.ProjectId &&
                                               p.DeletedByUserId == null &&
                                               p.Members.Any(m => m.MemberId == userId && HeadOfProjectRoles.Contains(m.Role)));

            if (project == null)
            {
                return(ServiceResult <MemberModel> .NotFound("Project not found or you are cant moderate it"));
            }

            var alreadyExistMember = project.Members.Any(m => m.MemberId == model.MemberId);

            if (alreadyExistMember)
            {
                return(ServiceResult <MemberModel> .Error("User already in project"));
            }

            var newMember = (Member) new Member(userId).InjectFrom(model);

            project.Members.Add(newMember);
            var count = await _dbContext.SaveChangesAsync();

            if (count != 1)
            {
                return(ServiceResult <MemberModel> .Error("Something went wrong"));
            }

            var memberModel = (MemberModel) new MemberModel().InjectFrom(newMember);

            return(ServiceResult <MemberModel> .Ok(memberModel));
        }
Exemple #2
0
 public async Task <bool> IsMember(string projectId, string userId, bool isModerator = false) =>
 await _dbContext.Projects
 .AnyAsync(p => p.Id == projectId &&
           p.Members.Any(m => m.MemberId == userId && (!isModerator || HeadOfProjectRoles.Contains(m.Role))) &&
           p.DeletedAt == null);