Пример #1
0
        public async Task <PagedResult <UserVm> > GetUsersPaging(GetUsersPagingRequest request)
        {
            var query = _userManager.Users;

            if (!string.IsNullOrEmpty(request.Keyword))
            {
                query = query.Where(x => x.UserName.Contains(request.Keyword) || x.PhoneNumber.Contains(request.Keyword));
            }
            //paging
            int totalRow = await query.CountAsync();

            var data = await query.Skip((request.PageIndex - 1) *request.PageSize)
                       .Take(request.PageSize)
                       .Select(
                x => new UserVm()
            {
                Email       = x.Email,
                FirstName   = x.FirstName,
                LastName    = x.LastName,
                UserName    = x.UserName,
                Id          = x.Id,
                PhoneNumber = x.PhoneNumber
            }
                ).ToListAsync();

            // select
            var pagedResult = new PagedResult <UserVm>()
            {
                TotalRecord = totalRow,
                Items       = data,
            };

            return(pagedResult);
        }
Пример #2
0
        public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10)
        {
            var session = HttpContext.Session.GetString("Token");
            //if (session == null)
            //    return RedirectToAction("Index", "Login");
            var request = new GetUsersPagingRequest()
            {
                BearerToken = session,
                Keyword     = keyword,
                PageIndex   = pageIndex,
                PageSize    = pageSize,
            };
            var data = await _userApiClient.GetUsersPaging(request);

            return(View(data));
        }
Пример #3
0
        public async Task <PagedResult <UserVm> > GetUsersPaging(GetUsersPagingRequest request)
        {
            var client = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri(_iconfiguration["BaseAddress"]);
            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", request.BearerToken);

            var response = await client.GetAsync($"/api/users/paging?pageIndex={request.PageIndex}" +
                                                 $"&pageSize={request.PageSize}&keyword={request.Keyword}");

            var body = await response.Content.ReadAsStringAsync();

            var users = JsonConvert.DeserializeObject <PagedResult <UserVm> >(body);

            return(users);
        }
Пример #4
0
        public async Task <IActionResult> GetAllPaging([FromQuery] GetUsersPagingRequest request)
        {
            var products = await _userService.GetUsersPaging(request);

            return(Ok(products));
        }
Пример #5
0
 /// <remarks/>
 public void GetUsersPagingAsync(GetUsersPagingRequest GetUsersPagingRequest, object userState) {
     if ((this.GetUsersPagingOperationCompleted == null)) {
         this.GetUsersPagingOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetUsersPagingOperationCompleted);
     }
     this.InvokeAsync("GetUsersPaging", new object[] {
                 GetUsersPagingRequest}, this.GetUsersPagingOperationCompleted, userState);
 }
Пример #6
0
 /// <remarks/>
 public void GetUsersPagingAsync(GetUsersPagingRequest GetUsersPagingRequest) {
     this.GetUsersPagingAsync(GetUsersPagingRequest, null);
 }