Esempio n. 1
0
        public static IQueryable <T> ApplySort <T>(this IQueryable <T> query, QueryCriteria criteria)
        {
            var sortBy        = criteria.SortBy;
            var sortDirection = criteria.SortDirection;

            if (sortBy == null || typeof(T).GetProperty(sortBy, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance) == null)
            {
                var property = typeof(T).GetProperties().FirstOrDefault(p => p.IsDefined(typeof(SortAttribute)));
                if (property != null)
                {
                    var attribute = property.GetCustomAttribute <SortAttribute>() !;
                    sortBy        = property.Name;
                    sortDirection = attribute.SortDirection;
                }
            }
            if (sortBy == null)
            {
                return(query);
            }
            return(query.OrderBy(sortBy, sortDirection));
        }
Esempio n. 2
0
 public static IQueryable <T> ApplyPreFilters <T>(this IQueryable <T> query, QueryCriteria criteria) => query.ApplyFilters(criteria.PreFilters, true);
Esempio n. 3
0
 public static IQueryable <T> ApplyPostFilters <T>(this IQueryable <T> query, QueryCriteria criteria) => query.ApplyFilters(criteria.PostFilters, false);
Esempio n. 4
0
 public static IQueryable <T> ApplyAllFilters <T>(this IQueryable <T> query, QueryCriteria criteria) => query.ApplyPreFilters(criteria).ApplyPostFilters(criteria);