예제 #1
0
        public async Task <IActionResult> GetUsers([FromQuery] UserPaginationParams userPaginationParams)
        {
            var users = await database.AdminRepository.GetPagedUsers(userPaginationParams);

            var usersToReturn = mapper.Map <ICollection <UserAdminListDto> >(users);

            Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages);

            return(Ok(usersToReturn));
        }
예제 #2
0
        public async Task <PagedList <User> > GetPagedUsers(UserPaginationParams userPaginationParams)
        {
            var users = await GetAll <User>();

            users = users.OrderByDescending(u => u.Id);

            if (!string.IsNullOrEmpty(userPaginationParams.BlockStatus))
            {
                switch (userPaginationParams.BlockStatus)
                {
                case "All": break;

                case "Blocked":
                    users = users.Where(u => u.IsBlocked);
                    break;

                case "NotBlocked":
                    users = users.Where(u => !u.IsBlocked);
                    break;

                default: break;
                }
            }

            if (userPaginationParams.IsOnlyAdmins)
            {
                users = users.Where(u => u.UserRoles
                                    .Any(ur => ur.Role.Name == "Admin" || ur.Role.Name == "HeadAdmin"));
            }

            if (userPaginationParams.IsSchoolOwner)
            {
                users = users.Where(u => u.UserRoles.Any(ur => ur.Role.Name == "SchoolOwner"));
            }

            if (!string.IsNullOrEmpty(userPaginationParams.UserName))
            {
                users = users.Where(u => u.UserName.ToLower()
                                    .Contains(userPaginationParams.UserName.ToLower()));
            }

            if (!string.IsNullOrEmpty(userPaginationParams.EmailConfirmed))
            {
                switch (userPaginationParams.EmailConfirmed)
                {
                case "All": break;

                case "True":
                    users = users.Where(u => u.EmailConfirmed);
                    break;

                case "False":
                    users = users.Where(u => !u.EmailConfirmed);
                    break;

                default: break;
                }
            }

            if (!userPaginationParams.IsDescendingId)
            {
                users = users.OrderBy(u => u.Id);
            }

            return(PagedList <User> .Create(users.AsQueryable(), userPaginationParams.PageNumber, userPaginationParams.PageSize));
        }