private 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); } }
public IList <string> GetWallUsersEmails(string senderEmail, WallModel wall) { var newUserAndExternalRoles = _rolesDbSet .Where(r => r.Name == Constants.Authorization.Roles.NewUser || r.Name == Constants.Authorization.Roles.External) .ToList(); var newUserRoleId = newUserAndExternalRoles.First(r => r.Name == Constants.Authorization.Roles.NewUser).Id; var externalRoleId = newUserAndExternalRoles.First(r => r.Name == Constants.Authorization.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); }