示例#1
0
 private static Expression <Func <ApplicationUser, bool> > ExternalRoleFilter(WallModel wall, string externalRoleId)
 {
     if (wall.Type != WallType.Events)
     {
         return(user => user.Roles.All(r => r.RoleId != externalRoleId));
     }
     else
     {
         return(user => true);
     }
 }
        private static void JoinWall(string userId, MultiwallWall wall)
        {
            var newMember = new WallMember
            {
                UserId = userId,
                WallId = wall.Id,
                AppNotificationsEnabled   = true,
                EmailNotificationsEnabled = true
            };

            wall.Members.Add(newMember);
        }
示例#3
0
        public async Task <int> CreateNewWallAsync(CreateWallDto newWallDto)
        {
            var alreadyExists = await _wallsDbSet
                                .AnyAsync(w =>
                                          w.OrganizationId == newWallDto.OrganizationId &&
                                          w.Name == newWallDto.Name &&
                                          (w.Type == WallType.UserCreated ||
                                           w.Type == WallType.Main));

            if (alreadyExists)
            {
                throw new ValidationException(ErrorCodes.WallNameAlreadyExists, "Wall name already exists");
            }

            if (newWallDto.MembersIds == null || newWallDto.MembersIds.Any())
            {
                newWallDto.MembersIds = newWallDto.ModeratorsIds;
            }
            else
            {
                newWallDto.MembersIds = newWallDto.MembersIds.Union(newWallDto.ModeratorsIds);
            }

            var wall = new MultiwallWall
            {
                Access         = newWallDto.Access,
                Type           = newWallDto.Type == WallType.Main ? WallType.UserCreated : newWallDto.Type,
                OrganizationId = newWallDto.OrganizationId,
                Name           = newWallDto.Name,
                Logo           = newWallDto.Logo,
                Description    = newWallDto.Description,
                Moderators     = newWallDto.ModeratorsIds.Select(x => new WallModerator
                {
                    UserId = x
                }).ToList(),
                IsHiddenFromAllWalls = newWallDto.IsHiddenFromAllWalls,
                Members = newWallDto.MembersIds.Select(x => new WallMember
                {
                    UserId = x,
                    AppNotificationsEnabled   = true,
                    EmailNotificationsEnabled = true
                }).ToList()
            };

            _wallsDbSet.Add(wall);
            await _uow.SaveChangesAsync(newWallDto.UserId);

            return(wall.Id);
        }
        private void LeaveWall(string userId, MultiwallWall wall)
        {
            var isModerator = wall.Moderators.Any(m => m.UserId == userId && m.WallId == wall.Id);

            if (isModerator && wall.Type == WallType.UserCreated)
            {
                throw new ValidationException(ErrorCodes.WallModeratorCanNotLeave, "Moderator can not leave wall");
            }

            if (wall.Type == WallType.Main)
            {
                throw new ValidationException(ErrorCodes.WallCannotLeaveMain, "Can not leave main wall");
            }

            var member = wall.Members.First(x => x.UserId == userId);

            _wallUsersDbSet.Remove(member);
        }
示例#5
0
        public IList <string> GetWallUsersEmails(string senderEmail, WallModel wall)
        {
            var newUserAndExternalRoles = _rolesDbSet
                                          .Where(r => r.Name == Contracts.Constants.Roles.NewUser ||
                                                 r.Name == Contracts.Constants.Roles.External)
                                          .ToList();

            var newUserRoleId  = newUserAndExternalRoles.First(r => r.Name == Contracts.Constants.Roles.NewUser).Id;
            var externalRoleId = newUserAndExternalRoles.First(r => r.Name == Contracts.Constants.Roles.External).Id;

            var emails = _usersDbSet
                         .Include(u => u.WallUsers)
                         .Include(u => u.Roles)
                         .Where(user => user.WallUsers.Any(x => x.WallId == wall.Id && x.EmailNotificationsEnabled) &&
                                user.Roles.All(r => r.RoleId != newUserRoleId) &&
                                user.Email != senderEmail)
                         .Where(ExternalRoleFilter(wall, externalRoleId))
                         .Select(u => u.Email)
                         .Distinct()
                         .ToList();

            return(emails);
        }