public static IPagedList <TSource> SortToPagedList <TSource>(this IQueryable <TSource> source, PagingCriteria pagingCriteria)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (pagingCriteria == null)
            {
                throw new ArgumentNullException("pagingCriteria");
            }
            var sortedSource = source.SortBySortField(pagingCriteria.SortFields.ToArray());

            if (pagingCriteria.IsNotPaged)
            {
                var count    = sortedSource.Count();
                var pageSize = count == 0 ? 1 : count;
                return(sortedSource.ToPagedList(1, pageSize));
            }
            return(sortedSource.ToPagedList(pagingCriteria.Page, pagingCriteria.PageSize));
        }
 public static IPagedList <TSource> SortToPagedList <TSource>(this IEnumerable <TSource> source, PagingCriteria pagingCriteria)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     return(source.AsQueryable().SortToPagedList(pagingCriteria));
 }