public async Task <IActionResult> GetAllWithPaging([FromQuery] GetQLQuanHamPagingRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _qLQuanHamServices.GetAllWithPaging(request); if (result.ResultObj != null) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 5) { var pageResult = new GetQLQuanHamPagingRequest() { keyword = keyword, pageIndex = pageIndex, pageSize = pageSize }; var result = await _qLQuanHamApiClient.GetAllWithPaging(pageResult); if (result.ResultObj != null) { if (TempData["result"] != null) { ViewBag.Success = true; ViewBag.SuccessMessage = TempData["result"]; } return(View(result.ResultObj)); } return(View(result)); }
public async Task <APIResult <PageResult <QLQuanHamViewModel> > > GetAllWithPaging(GetQLQuanHamPagingRequest request) { var query = from qlqh in _context.QLQuanHams join qh in _context.QuanHams on qlqh.IDQH equals qh.IDQH join hsltqh in _context.HeSoLuongTheoQuanHams on qlqh.IDHeSoLuongTheoQH equals hsltqh.IDHeSoLuongQH join sq in _context.SiQuans on qlqh.IDSQ equals sq.IDSQ select new QLQuanHamViewModel() { IDQLQH = qlqh.IDQLQH, IDSQ = qlqh.IDSQ, HoTen = sq.HoTen, TenQH = qh.TenQH, TenHeSoLuongQH = hsltqh.TenHeSoLuongQH }; var totalRow = await query.CountAsync(); var data = await query.Skip((request.pageIndex - 1) *request.pageSize) .Take(request.pageSize) .Select(x => new QLQuanHamViewModel() { IDQLQH = x.IDQLQH, IDSQ = x.IDSQ, HoTen = x.HoTen, TenQH = x.TenQH, TenHeSoLuongQH = x.TenHeSoLuongQH }).ToListAsync(); var pageResult = new PageResult <QLQuanHamViewModel>() { TotalRecord = totalRow, PageIndex = request.pageIndex, PageSize = request.pageSize, Items = data }; return(new APISuccessedResult <PageResult <QLQuanHamViewModel> >(pageResult)); }
public async Task <APIResult <PageResult <QLQuanHamViewModel> > > GetAllWithPaging(GetQLQuanHamPagingRequest 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 response = await client.GetAsync($"/api/QLQuanHams/paging?pageIndex={request.pageIndex}&pageSize={request.pageSize}&keyword={request.keyword}"); var body = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <APISuccessedResult <PageResult <QLQuanHamViewModel> > >(body)); } return(JsonConvert.DeserializeObject <APIErrorResult <PageResult <QLQuanHamViewModel> > >(body)); }