protected override Expression <Func <Event, object> > GetSortExpression(BaseQuery query)
 {
     return(query.SortBy switch
     {
         "Name" => e => e.Name,
         "Date" => e => e.Date,
         _ => e => e.Id,
     });
        public IOrderedQueryable <T> ApplySorting(IQueryable <T> queryable, BaseQuery query)
        {
            var sortExpression = GetSortExpression(query);

            return(query.SortOrder switch
            {
                SortOrder.Descending => queryable.OrderByDescending(sortExpression),
                _ => queryable.OrderBy(sortExpression)
            });
Ejemplo n.º 3
0
        public static IQueryable <T> ApplyPagination <T>(this IQueryable <T> queryable, BaseQuery query)
        {
            if (query.PageSize <= 0)
            {
                query.PageSize = 4;
            }

            if (query.Page <= 0)
            {
                query.Page = 1;
            }

            return(queryable.Skip(query.PageSize * (query.Page - 1)).Take(query.PageSize));
        }