예제 #1
0
 protected override Expression <Func <Event, object> > GetSortExpression(BaseQuery query)
 {
     return(query.SortBy switch
     {
         SortBy.Date => p => p.Date,
         SortBy.Name => p => p.Name
     });
예제 #2
0
        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));
        }