Beispiel #1
0
        public async Task <PageResultDto <UserDto> > GetAllPaging(GetUserPagingRequestDto request)
        {
            var query = _userManager.Users.Where(x => x.IsDeleted == false).AsQueryable();

            if (!string.IsNullOrEmpty(request.UserName))
            {
                query = query.Where(x => x.UserName.Contains(request.UserName));
            }
            if (!string.IsNullOrEmpty(request.FullName))
            {
                query = query.Where(x => x.FullName.Contains(request.FullName));
            }
            if (!string.IsNullOrEmpty(request.PhoneNumber))
            {
                query = query.Where(x => x.PhoneNumber.Contains(request.PhoneNumber));
            }
            if (request.TypeAccount >= 0)
            {
                query = query.Where(x => x.TypeAccount == (TypeAccount)request.TypeAccount);
            }
            //3. Paging
            int totalRow = await query.CountAsync();

            var data = await query.Skip((request.PageIndex - 1) *request.PageSize)
                       .Take(request.PageSize)
                       .Select(x => new UserDto()
            {
                Email       = x.Email,
                PhoneNumber = x.PhoneNumber,
                UserName    = x.UserName,
                Id          = x.Id,
                TypeAccount = (int)x.TypeAccount,
                FullName    = x.FullName,
                Dob         = x.Dob,
                Status      = (int)x.Status,
                Roles       = null
            }).ToListAsync();

            //4. Select and projection
            var pagedResult = new PageResultDto <UserDto>()
            {
                StatusCode  = ResponseCode.Success,
                Message     = "Thành công",
                TotalRecord = totalRow,
                Items       = data
            };

            return(pagedResult);
        }
        public async Task <PageResultDto <UserDto> > GetAllPaging([FromQuery] GetUserPagingRequestDto request)
        {
            var result = await _userService.GetAllPaging(request);

            return(result);
        }