public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10) { var request = new GetQuanHamPagingRequest() { keyword = keyword, pageIndex = pageIndex, pageSize = pageSize }; if (TempData["result"] != null) { ViewBag.Success = true; ViewBag.SuccessMessage = TempData["result"]; } var result = await _quanHamApiClient.GetAllWithPaging(request); return(View(result.ResultObj)); }
public async Task <APIResult <PageResult <QuanHamViewModel> > > GetAllWithPaging(GetQuanHamPagingRequest request) { var query = from qh in _context.QuanHams select qh; if (!string.IsNullOrEmpty(request.keyword)) { query = query.Where(x => x.IDQH.ToString().Contains(request.keyword) || x.TenQH.Contains(request.keyword)); } int totalrow = await query.CountAsync(); var data = await query.Skip((request.pageIndex - 1) *request.pageSize) .Take(request.pageSize) .Select(x => new QuanHamViewModel() { IDQH = x.IDQH, TenQH = x.TenQH }).ToListAsync(); var pageresult = new PageResult <QuanHamViewModel>() { TotalRecord = totalrow, PageIndex = request.pageIndex, PageSize = request.pageSize, Items = data }; return(new APISuccessedResult <PageResult <QuanHamViewModel> >(pageresult)); }
public async Task <IActionResult> GetAllWithPaging([FromQuery] GetQuanHamPagingRequest request) { var qlqh = await _quanHamServices.GetAllWithPaging(request); return(Ok(qlqh)); }
public async Task <APIResult <PageResult <QuanHamViewModel> > > GetAllWithPaging(GetQuanHamPagingRequest request) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); var session = _httpContextAccessor.HttpContext.Session.GetString("Token"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", session); var reponse = await client.GetAsync($"/api/QuanHams/paging?pageIndex={request.pageIndex}&pageSize={request.pageSize}&keyword={request.keyword}"); var body = await reponse.Content.ReadAsStringAsync(); var user = JsonConvert.DeserializeObject <APISuccessedResult <PageResult <QuanHamViewModel> > >(body); return(user); }