Ejemplo n.º 1
0
        public async Task <PagedResult <UserView> > UserGetPaging(UserGetPagingRequest request)
        {
            var query = _userManager.Users;

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

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

            //SELECT
            var pagedResult = new PagedResult <UserView>()
            {
                TotalRecords = totalRow,
                PageSize     = request.PageSize,
                PageIndex    = request.PageIndex,
                Items        = data
            };

            return(pagedResult);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10)
        {
            var session = HttpContext.Session.GetString("Token");
            var request = new UserGetPagingRequest()
            {
                Keyword   = keyword,
                PageIndex = pageIndex,
                PageSize  = pageSize
            };
            var data = await _userClient.UserGetPaging(request);

            return(View(data));
        }
Ejemplo n.º 3
0
        public async Task <PagedResult <UserView> > UserGetPaging(UserGetPagingRequest request)
        {
            var client   = _httpClientFactory.CreateClient();
            var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token");

            client.BaseAddress = new Uri(_configuration["BaseAddress"]);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions);
            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 <UserView> >(body);

            return(users);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ProductGetByCategoryID([FromQuery] UserGetPagingRequest request)
        {
            var result = await _userService.UserGetPaging(request);

            return(Ok(result));
        }