/* public async Task<PagedResult<WorkViewModel>> GetAllpaging(string keywork, int pageIndex, int pageSize) * { * throw new NotImplementedException(); * }*/ public async Task <PagedResult <WorkViewModel> > GetAllpaging(WorkPagingRequest request) { var query = from w in _context.Works select new { w }; if (!string.IsNullOrEmpty(request.KeyWord)) { query = query.Where(x => x.w.Name.Contains(request.KeyWord)); } int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new WorkViewModel() { Id = x.w.Id, Name = x.w.Name, Description = x.w.Description, Status = (Data.Enums.Status)x.w.Status, Priority = (Data.Enums.Priority)x.w.Priority, Deadline = x.w.Deadline }).ToListAsync(); var pagedResult = new PagedResult <WorkViewModel>() { TotalRecords = totalRow, PageIndex = request.PageIndex, PageSize = request.PageSize, Items = data }; return(pagedResult); }
public async Task <IActionResult> GetAllPaging([FromQuery] WorkPagingRequest request) { var result = await _workSevice.GetAllpaging(request); if (result == null) { return(BadRequest("không tìm thấy gì...")); } return(Ok(result)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageZise = 5) { var request = new WorkPagingRequest() { KeyWord = keyword, PageIndex = pageIndex, PageSize = pageZise }; var data = await _workApiClient.GetWorkPaging(request); ViewBag.keyword = keyword; if (TempData["result"] != null) { ViewBag.SuccessMessage = TempData["result"]; } return(View(data)); }
public async Task <PagedResult <WorkViewModel> > GetWorkPaging(WorkPagingRequest request) { var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token"); var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); /*var response = await client.GetAsync( * $"/api/Works/paging?pageIndex={request.PageIndex}" + * $"&pageSize={request.PageSize}"+ * $"&keyword={request.KeyWork}");*/ var response = await client.GetAsync($"/api/works/paging?pageIndex=" + $"{request.PageIndex}&pageSize={request.PageSize}&keyword={request.KeyWord}"); var body = await response.Content.ReadAsStringAsync(); var works = JsonConvert.DeserializeObject <PagedResult <WorkViewModel> >(body); return(works); }