public async Task <PageResultDto <RouteDto> > GetAllPagingAsync(GetRoutePagingRequestDto request) { var query = _context.Routes.Where(x => x.IsDeleted == false).AsQueryable(); // Filter if (!string.IsNullOrEmpty(request.Name)) { query = query.Where(x => x.Name.Contains(request.Name)); } if (!string.IsNullOrEmpty(request.RouteCode)) { query = query.Where(x => x.RouteCode.Contains(request.RouteCode)); } if (request.Status >= 0) { query = query.Where(x => (int)x.Status == request.Status); } // Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new RouteDto() { Id = x.Id, Name = x.Name, Distance = x.Distance, RouteCode = x.RouteCode, Description = x.Desctiption, Status = (int)x.Status }).ToListAsync(); // Return var pageResult = new PageResultDto <RouteDto>() { TotalRecord = totalRow, Message = "Thực hiện thành công", Items = data }; return(pageResult); }
public async Task <PageResultDto <RouteDto> > GetAllPaging([FromQuery] GetRoutePagingRequestDto request) { var result = await _routeService.GetAllPagingAsync(request); return(result); }