private PaginationWebsitesDto GetResultPageAndCountProperties(PaginationWebsiteRequestDto request) { var result = new PaginationWebsitesDto(); result.TotalRecordCount = _context.Websites.Where(x => x.IsDeleted == false).Count(); result.PageNumber = GetPageNumber(request.PageNumber, request.PageSize, result.TotalRecordCount); result.TotalPagesCount = (int)Math.Ceiling((double)result.TotalRecordCount / request.PageSize); return(result); }
private static IQueryable <Website> ApplySorting(PaginationWebsiteRequestDto request, IQueryable <Website> query) { var sortExpression = GetSortExpression(request); if (request.SortOrder == SortOrder.Ascending) { query = query.OrderBy(sortExpression); } else { query = query.OrderByDescending(sortExpression); } return(query); }
public async Task <PaginationWebsitesDto> GetPaginationWebsites(PaginationWebsiteRequestDto request) { var result = GetResultPageAndCountProperties(request); var skip = (result.PageNumber - 1) * request.PageSize; var query = _context.Websites.Include(x => x.Login) .Include(x => x.Category) .Where(x => x.IsDeleted == false) .Skip(skip) .Take(request.PageSize); query = ApplySorting(request, query); result.Records = await query.ToListAsync(); return(result); }
private static Expression <Func <Website, string> > GetSortExpression(PaginationWebsiteRequestDto request) { Expression <Func <Website, string> > keySelector = null; if (request.OrderByProperty == SortOrderByProperty.Name) { keySelector = x => x.Name; } if (request.OrderByProperty == SortOrderByProperty.Category) { keySelector = x => x.Category.Name; } if (request.OrderByProperty == SortOrderByProperty.Email) { keySelector = x => x.Login.Email; } return(keySelector); }