public async Task <IActionResult> Index(string keyword, int groupType, int pageIndex = 1, int pageSize = 3) { var request = new GetProductTypePagingRequest() { Keyword = keyword, GroupType = groupType, PageIndex = pageIndex, PageSize = pageSize }; var data = await _productTypeApiClient.GetUsersPaging(request); ViewBag.Keyword = keyword; return(View(data.ResultObj)); }
public async Task <ApiResult <PagedResult <ProductTypeViewModel> > > GetUsersPaging(GetProductTypePagingRequest bundle) { var query = from s in _context.ProductTypes join g in _context.ProductTypeGroups on s.IdProductTypeGroup equals g.Id select new { s, g }; if (bundle.GroupType > 0) { query = query.Where(x => x.g.Id == bundle.GroupType); } if (!string.IsNullOrEmpty(bundle.Keyword)) { query = query.Where(c => c.s.Name.Contains(bundle.Keyword) || c.s.Code.Contains(bundle.Keyword)); } //3. Paging int totalRow = await query.CountAsync(); query = query.OrderByDescending(c => c.s.Id); var data = await query.Skip((bundle.PageIndex - 1) *bundle.PageSize) .Take(bundle.PageSize) .Select(i => new ProductTypeViewModel() { Id = i.s.Id, Code = i.s.Code, Name = i.s.Name, GroupType = i.g.Name }).ToListAsync(); //4. Select and projection var pagedResult = new PagedResult <ProductTypeViewModel>() { TotalRecords = totalRow, PageIndex = bundle.PageIndex, PageSize = bundle.PageSize, Items = data }; return(new ApiSuccessResult <PagedResult <ProductTypeViewModel> >(pagedResult)); }
public async Task <IActionResult> GetAllPaging([FromQuery] GetProductTypePagingRequest request) { var result = await _productTypeService.GetUsersPaging(request); return(Ok(result)); }
public async Task <ApiResult <PagedResult <ProductTypeViewModel> > > GetUsersPaging(GetProductTypePagingRequest bundle) { var url = $"/api/ProductType/paging?pageIndex=" + $"{bundle.PageIndex}&pageSize={bundle.PageSize}&keyword={bundle.Keyword}&grouptype={bundle.GroupType}"; var result = await GetListAsync <ProductTypeViewModel>(url); return(result); }