Exemple #1
0
        public static SortedQueryable <T> WithSorting <T>(this IQueryable <T> source, SortingHeader sortingHeader, ISorting sorting)
        {
            var validatedSortingHeader = DetermineSortingHeader <T>(sortingHeader, sorting);
            var orderedQueryable       = validatedSortingHeader.SortOrder == SortOrder.Ascending
                ? source.OrderBy(validatedSortingHeader.SortBy)
                : source.OrderByDescending(validatedSortingHeader.SortBy);

            return(new SortedQueryable <T>(orderedQueryable, validatedSortingHeader));
        }
Exemple #2
0
 private static bool SortingFieldSpecified(SortingHeader sortingHeader, ISorting sorting)
 {
     return(sortingHeader.ShouldSort &&
            sorting.SortableFields.Contains(sortingHeader.SortBy, StringComparer.OrdinalIgnoreCase));
 }
Exemple #3
0
 private static SortingHeader DetermineSortingHeader <T>(SortingHeader sortingHeader, ISorting sorting)
 {
     return(SortingFieldSpecified(sortingHeader, sorting)
         ? sortingHeader
         : sorting.DefaultSortingHeader);
 }
Exemple #4
0
        /// <summary>Add the 'x-sorting' response header</summary>
        public static void AddSortingResponse(this HttpResponse response, string sortBy, SortOrder sortOrder)
        {
            var sortingHeader = new SortingHeader(sortBy.ToLowerInvariant(), sortOrder);

            response.Headers.Add(HeaderName, JsonConvert.SerializeObject(sortingHeader));
        }
Exemple #5
0
 /// <summary>Add the 'x-sorting' response header</summary>
 public static void AddSortingResponse(this HttpResponse response, SortingHeader sortingHeader)
 => response.AddSortingResponse(sortingHeader.SortBy, sortingHeader.SortOrder);
Exemple #6
0
 public SortedQueryable(IQueryable <T> items, SortingHeader sortingHeader)
 {
     Items   = items;
     Sorting = sortingHeader;
 }