public async Task <IActionResult> GetAllWithPaging([FromQuery] GetQLChucVuPagingRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _qLChucVuServices.GetAllWithPaging(request); if (result.IsSuccessed) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 5) { var qlcvPagingRequest = new GetQLChucVuPagingRequest() { keyword = keyword, pageIndex = pageIndex, pageSize = pageSize }; var result = await _qLChucVuApiClient.GetAllWithPaging(qlcvPagingRequest); if (TempData["result"] != null) { ViewBag.Success = true; ViewBag.SuccessMessage = TempData["result"]; } return(View(result.ResultObj)); }
public async Task <APIResult <PageResult <QLChucVuViewModel> > > GetAllWithPaging(GetQLChucVuPagingRequest 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/QLChucVus/paging?pageIndex={request.pageIndex}&pageSize={request.pageSize}&keyword={request.keyword}"); var body = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <APISuccessedResult <PageResult <QLChucVuViewModel> > >(body)); } return(JsonConvert.DeserializeObject <APIErrorResult <PageResult <QLChucVuViewModel> > >(body)); }
public async Task <APIResult <PageResult <QLChucVuViewModel> > > GetAllWithPaging(GetQLChucVuPagingRequest request) { var query = from qlcv in _context.QLChucVus join sq in _context.SiQuans on qlcv.IDSQ equals sq.IDSQ join cv in _context.ChucVus on qlcv.IDCV equals cv.IDCV select new QLChucVuViewModel { IDQLCV = qlcv.IDQLCV, IDSQ = sq.IDSQ, HoTenSQ = sq.HoTen, IDCV = cv.IDCV, TenCV = cv.TenCV, NgayNhan = qlcv.NgayNhan }; if (!string.IsNullOrEmpty(request.keyword)) { query = query.Where(x => x.HoTenSQ.Contains(request.keyword) || x.TenCV.Contains(request.keyword)); } var totalRow = await query.CountAsync(); var data = await query.Skip((request.pageIndex - 1) *request.pageSize) .Take(request.pageSize) .Select(x => new QLChucVuViewModel { IDQLCV = x.IDQLCV, IDSQ = x.IDSQ, HoTenSQ = x.HoTenSQ, IDCV = x.IDCV, TenCV = x.TenCV, NgayNhan = x.NgayNhan }).ToListAsync(); var pageresult = new PageResult <QLChucVuViewModel>() { TotalRecord = totalRow, PageIndex = request.pageIndex, PageSize = request.pageSize, Items = data }; var s = data; return(new APISuccessedResult <PageResult <QLChucVuViewModel> >(pageresult)); }