protected override Expression <Func <Event, object> > GetSortExpression(BaseQuery query) { return(query.SortBy switch { SortBy.Date => p => p.Date, SortBy.Name => p => p.Name });
public IOrderedQueryable <T> ApplySorting(IQueryable <T> queryable, BaseQuery query) { var sortExpression = GetSortExpression(query); return(query.SortOrder switch { SortOrder.Desc => queryable.OrderByDescending(sortExpression), SortOrder.Asc => queryable.OrderBy(sortExpression) });
public static IQueryable <T> ApplyPagination <T>(this IQueryable <T> queryable, BaseQuery query) { if (query.PageSize <= 0) { query.PageSize = 10; } if (query.Page <= 0) { query.Page = 1; } return(queryable.Skip(query.PageSize * (query.Page - 1)).Take(query.PageSize)); }