public List <int> FindUserIds(string filter)
 {
     using (var dnnDb = DnnDbContext.Instantiate())
     {
         return(dnnDb.vw_Users
                .Where(u => u.DisplayName.Contains(filter) ||
                       u.FirstName.Contains(filter) ||
                       u.LastName.Contains(filter) ||
                       u.Email.Contains(filter))
                .Select(u => u.UserID)
                .ToList());
     }
 }
        public List <CustomerAccount> FindByFilter(string filter, int pageNumber, int pageSize, ref int totalCount)
        {
            var pageIndex = GetPageIndex(pageNumber);
            IEnumerable <UserInfo> users = null;

            if (string.IsNullOrEmpty(filter))
            {
                users = UserController.GetUsers(PortalId, pageIndex, pageSize, ref totalCount)
                        .OfType <UserInfo>();
            }
            else
            {
                using (var dnnDb = DnnDbContext.Instantiate())
                {
                    var userIds = dnnDb.vw_Users
                                  .Where(u =>
                                         u.Email.Contains(filter) ||
                                         (u.Username != null && u.Username.Contains(filter)) ||
                                         (u.FirstName != null && u.FirstName.Contains(filter)) ||
                                         (u.LastName != null && u.LastName.Contains(filter)) ||
                                         (u.DisplayName != null && u.DisplayName.Contains(filter)))
                                  .OrderBy(u => u.Username)
                                  .Select(u => u.UserID)
                                  .ToList();

                    userIds.AddRange(dnnDb.vw_Profile
                                     .Where(p => p.PropertyValue.Contains(filter) ||
                                            p.PropertyValue.Contains(filter))
                                     .OrderBy(u => u.UserID)
                                     .Select(u => u.UserID)
                                     .ToList());

                    userIds    = userIds.Distinct().ToList();
                    totalCount = userIds.Count();
                    var filteredIds = userIds.Skip(pageIndex * pageSize).Take(pageSize);
                    var usersInfo   = new List <UserInfo>();
                    foreach (var id in filteredIds)
                    {
                        usersInfo.Add(UserController.GetUserById(PortalId, id));
                    }
                    users = usersInfo;
                }
            }
            return(users.Select(UserInfoToCustomer).ToList());
        }
            public List <DnnUser> GetUsersFromDb(int portalId, List <int> userIds)
            {
                using (var dnnDb = DnnDbContext.Instantiate())
                {
                    var usersAndProfile = dnnDb.vw_Users
                                          .Where(u => userIds.Contains(u.UserID))
                                          .Join(dnnDb.vw_Profile, u => u.UserID, p => p.UserID, (u, p) => new { User = u, Profile = p })
                                          .GroupBy(up => up.User.UserID)
                                          .ToList();

                    return(usersAndProfile.Select(up =>
                    {
                        var u = up.First().User;
                        u.Profile = up.Select(upi => upi.Profile).ToList();
                        return u;
                    }).ToList());
                }
            }