Ejemplo n.º 1
0
        public async Task <IActionResult> Index(string search, string sort, int page = 1)
        {
            int take = 15;
            int skip = take * (page - 1);

            DataWithCount <IEnumerable <User> > participantsList = new DataWithCount <IEnumerable <User> >();

            if (!string.IsNullOrWhiteSpace(sort) && Enum.IsDefined(typeof(SortUsersBy), sort))
            {
                SortUsersBy userSort = (SortUsersBy)Enum.Parse(typeof(SortUsersBy), sort);
                participantsList = await _userService
                                   .GetPaginatedUserListAsync(skip, take, search, userSort);
            }
            else
            {
                participantsList = await _userService
                                   .GetPaginatedUserListAsync(skip, take, search);
            }

            PaginateViewModel paginateModel = new PaginateViewModel()
            {
                ItemCount    = participantsList.Count,
                CurrentPage  = page,
                ItemsPerPage = take
            };

            if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            ParticipantsListViewModel viewModel = new ParticipantsListViewModel()
            {
                Users                = participantsList.Data,
                PaginateModel        = paginateModel,
                Search               = search,
                CanRemoveParticipant = UserHasPermission(Permission.DeleteParticipants),
                CanViewDetails       = UserHasPermission(Permission.ViewParticipantDetails),
                SortUsers            = Enum.GetValues(typeof(SortUsersBy))
            };

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        // *********************************************************************
        //  GetAllUsers
        //
        /// <summary>
        /// Returns all the users currently in the system.
        /// </summary>
        /// <param name="pageIndex">Page position in which to return user's for, e.g. position of result set</param>
        /// <param name="pageSize">Size of a given page, e.g. size of result set.</param>
        /// <param name="sortBy">How the returned user's are to be sorted.</param>
        /// <param name="sortOrder">Direction in which to sort</param>
        /// <returns>A collection of user.</returns>
        ///
        // ********************************************************************/
        public static UserCollection GetAllUsers(int pageIndex, int pageSize, SortUsersBy sortBy, int sortOrder, string usernameBeginsWith)
        {
            UserCollection users;

            // Build a cache key
            string usersKey = pageIndex.ToString() + pageSize.ToString() + sortBy + sortOrder.ToString() + usernameBeginsWith;

            // Serve from the cache when possible
            users = (UserCollection)HttpContext.Current.Cache[usersKey];

            if (users == null)
            {
                // Create Instance of the IDataProviderBase
                IDataProviderBase dp = DataProvider.Instance();

                users = dp.GetAllUsers(pageIndex, pageSize, sortBy, sortOrder, usernameBeginsWith);

                // Insert the user collection into the cache for 120 seconds
                HttpContext.Current.Cache.Insert(usersKey, users, null, DateTime.Now.AddSeconds(1800), TimeSpan.Zero);
            }

            return(users);
        }
Ejemplo n.º 3
0
 public GetUsersParams(int limit, int offset, SortUsersBy sortUsersBy)
 {
     Limit       = limit;
     Offset      = offset;
     SortUsersBy = sortUsersBy;
 }
Ejemplo n.º 4
0
 public abstract UserSet UsersInRole(int pageIndex, int pageSize, SortUsersBy sortBy, SortOrder sortOrder, Guid roleID, UserAccountStatus accountStatus, bool returnRecordCount);
Ejemplo n.º 5
0
 public abstract UserSet GetUsers(int pageIndex, int pageSize, SortUsersBy sortBy, SortOrder sortOrder, string usernameFilter, bool includeEmailInFilter, UserAccountStatus accountStatus, bool returnRecordCount, bool includeHiddenUsers, bool returnModerationCounters);
Ejemplo n.º 6
0
Archivo: Users.cs Proyecto: pcstx/OA
        public static UserSet GetUsers(int pageIndex, int pageSize, SortUsersBy sortBy, SortOrder sortOrder, string usernameFilter, bool includeEmailInFilter, bool cacheable, UserAccountStatus accountStatus, bool returnRecordCount, bool includeHiddenUsers)
        {
            HttpContext context = HttpContext.Current;
            UserSet users;
            // Return moderation counters also
            //
            bool returnModerationCounters = CSContext.Current.SiteSettings.EnableUserModerationCounters;

            // If we're compiled with debug code we never cache
            //
            #if DEBUG_NOCACHE
            cacheable = false;
            #endif

            if (cacheable) {

                // Build a cache key
                //
                string usersKey = pageIndex.ToString() + pageSize.ToString() + sortBy + sortOrder + usernameFilter + includeEmailInFilter + accountStatus + returnModerationCounters;

                // Serve from the cache when possible
                //
                users = CSCache.Get(usersKey) as UserSet;

                if (users == null) {

                    users = GetUsersFromDataProvider (pageIndex, pageSize, sortBy, sortOrder, usernameFilter, includeEmailInFilter, accountStatus, returnRecordCount, includeHiddenUsers, returnModerationCounters);

                    // Insert the user collection into the cache for 30 seconds
                    CSCache.Insert(usersKey, users, CSCache.MinuteFactor / 2);

                }

            } else {

                users = GetUsersFromDataProvider(pageIndex, pageSize, sortBy, sortOrder, usernameFilter, includeEmailInFilter, accountStatus, returnRecordCount, includeHiddenUsers, returnModerationCounters);

            }

            return users;
        }
Ejemplo n.º 7
0
Archivo: Users.cs Proyecto: pcstx/OA
        private static UserSet GetUsersFromDataProvider(int pageIndex, int pageSize, SortUsersBy sortBy, SortOrder sortOrder, string usernameFilter, bool includeEmailInFilter, UserAccountStatus accountStatus, bool returnRecordCount, bool includeHiddenUsers, bool returnModerationCounters)
        {
            // Create Instance of the CommonDataProvider
            CommonDataProvider dp = CommonDataProvider.Instance();

            return dp.GetUsers(pageIndex, pageSize, sortBy, sortOrder, usernameFilter, includeEmailInFilter, accountStatus, returnRecordCount, includeHiddenUsers, returnModerationCounters );
        }
 /// <summary>
 /// Gets users from the network sorted using the provided criterion
 /// </summary>
 /// <param name="instance">The instance</param>
 /// <param name="sortUsersBy">The desired sort</param>
 /// <returns></returns>
 public static IYammerUsersSorted SortedBy(this IYammerUsers instance, SortUsersBy sortUsersBy)
 {
     instance.Root.Parameters.SortUsersBy = sortUsersBy;
     return new YammerUsersSorted(instance.Root);
 }
Ejemplo n.º 9
0
Archivo: Roles.cs Proyecto: pcstx/OA
        public static UserSet UsersInRole(int pageIndex, int pageSize, SortUsersBy sortBy, SortOrder sortOrder, Guid roleID, bool cacheable, UserAccountStatus accountStatus, bool returnRecordCount)
        {
            UserSet u = null;

            // build a unique cache key
            StringBuilder s = new StringBuilder();
            s.Append("UsersInRole-");
            s.Append(pageIndex.ToString());
            s.Append(pageSize.ToString());
            s.Append(sortBy.ToString());
            s.Append(sortOrder.ToString());
            s.Append(roleID.ToString());
            s.Append(accountStatus.ToString());
            s.Append(returnRecordCount.ToString());

            string cacheKey =  s.ToString();

            // Get the data from the data provider if not in the cache
            //
            u = CSCache.Get(cacheKey) as UserSet;
            if (u == null || !cacheable) {
                CommonDataProvider dp = CommonDataProvider.Instance();
                u = dp.UsersInRole(pageIndex, pageSize, sortBy, sortOrder, roleID, accountStatus, returnRecordCount);

                if (cacheable)
                    CSCache.Insert(cacheKey,u,12 * CSCache.HourFactor);
            }
            return u;
        }
Ejemplo n.º 10
0
Archivo: Roles.cs Proyecto: pcstx/OA
 public static UserSet UsersInRole(int pageIndex, int pageSize, SortUsersBy sortBy, SortOrder sortOrder, Guid roleID)
 {
     return UsersInRole(pageIndex, pageSize, sortBy, sortOrder, roleID, true, UserAccountStatus.Approved, true);
 }
Ejemplo n.º 11
0
        } // FetchAll

        /// <summary>
        /// gets an Array of all WebPortalUsers that are in a specified role
        /// </summary>
        /// <param name="role">the (case insensitive) role to find all users for</param>
        /// <returns>an ArrayList of WebPortalUser Objects</returns>
        public static WebPortalUser[] FetchAll(WebPortalUserRole inRole, SortUsersBy sortBy, PortalApplication portalApp)
        {
            return((new WebPortalUserDB()).FetchAllWebPortalUsers(inRole, sortBy, portalApp));
        } // FetchAll
Ejemplo n.º 12
0
        } // getAllUsers

        public static WebPortalUser[] FetchAll(SortUsersBy sortBy, PortalApplication portalApp)
        {
            return((new WebPortalUserDB()).FetchAllWebPortalUsers(sortBy, portalApp));
        } // getAllUsers
Ejemplo n.º 13
0
        public async Task <IEnumerable <User> > PageAllAsync(int siteId,
                                                             int skip,
                                                             int take,
                                                             string search      = null,
                                                             SortUsersBy sortBy = SortUsersBy.LastName)
        {
            var userList = DbSet
                           .AsNoTracking()
                           .Include(_ => _.Branch)
                           .Include(_ => _.Program)
                           .Include(_ => _.System);

            IQueryable <Model.User> filteredUserList = null;

            if (string.IsNullOrEmpty(search))
            {
                filteredUserList = userList.Where(_ => _.IsDeleted == false &&
                                                  _.SiteId == siteId);
            }
            else
            {
                filteredUserList = userList.Where(_ => _.IsDeleted == false &&
                                                  _.SiteId == siteId &&
                                                  (_.Username.Contains(search) ||
                                                   _.FirstName.Contains(search) ||
                                                   _.LastName.Contains(search) ||
                                                   _.Email.Contains(search) ||
                                                   (_.FirstName + " " + _.LastName).Contains(search) ||
                                                   (_.LastName + " " + _.FirstName).Contains(search)));
            }

            switch (sortBy)
            {
            case SortUsersBy.FirstName:
                filteredUserList = filteredUserList
                                   .OrderBy(_ => _.FirstName)
                                   .ThenBy(_ => _.LastName)
                                   .ThenBy(_ => _.Username);
                break;

            case SortUsersBy.LastName:
                filteredUserList = filteredUserList
                                   .OrderBy(_ => _.LastName)
                                   .ThenBy(_ => _.FirstName)
                                   .ThenBy(_ => _.Username);
                break;

            case SortUsersBy.RegistrationDate:
                filteredUserList = filteredUserList
                                   .OrderBy(_ => _.CreatedAt)
                                   .ThenBy(_ => _.LastName)
                                   .ThenBy(_ => _.FirstName)
                                   .ThenBy(_ => _.Username);
                break;

            case SortUsersBy.Username:
                filteredUserList = filteredUserList
                                   .OrderBy(_ => _.Username)
                                   .ThenBy(_ => _.LastName)
                                   .ThenBy(_ => _.FirstName);
                break;
            }

            return(await filteredUserList
                   .Skip(skip)
                   .Take(take)
                   .ProjectTo <User>()
                   .ToListAsync());
        }
Ejemplo n.º 14
0
        public async Task <DataWithCount <IEnumerable <User> > > GetPaginatedUserListAsync(int skip,
                                                                                           int take,
                                                                                           string search      = null,
                                                                                           SortUsersBy sortBy = SortUsersBy.LastName)
        {
            int siteId = GetClaimId(ClaimType.SiteId);

            if (HasPermission(Permission.ViewParticipantList))
            {
                return(new DataWithCount <IEnumerable <User> >
                {
                    Data = await _userRepository.PageAllAsync(siteId, skip, take, search, sortBy),
                    Count = await _userRepository.GetCountAsync(siteId, search)
                });
            }
            else
            {
                int userId = GetClaimId(ClaimType.UserId);
                _logger.LogError($"User {userId} doesn't have permission to view all participants.");
                throw new GraException("Permission denied.");
            }
        }