public static Page <TSource> ToPage <TSource>(this IList <TSource> source, int totalRecordCount, Paging paging)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var skipCount = PagingExtensions.GetSkipCount(paging);
            var page      = new Page <TSource>
            {
                HasNext          = paging != null && totalRecordCount > 0 && skipCount + paging.RecordsPerPage < totalRecordCount,
                HasPrevious      = paging != null && totalRecordCount > 0 && skipCount > 0,
                TotalPageCount   = paging == null ? 1 : paging.RecordsPerPage == 0 ? 0 : (int)Math.Ceiling((float)totalRecordCount / (float)paging.RecordsPerPage),
                PageNumber       = paging?.PageNumber ?? 0,
                RecordsPerPage   = paging?.RecordsPerPage ?? 0,
                TotalRecordCount = totalRecordCount,
                Items            = source.ToList(),
            };

            return(page);
        }
        public static IQueryable <TSource> TakePage <TSource>(this IQueryable <TSource> source, Paging paging)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (paging == null)
            {
                return(source);
            }

            if (paging.SortInfo != null && paging.SortInfo.Any())
            {
                var orderings = string.Join(", ", paging.SortInfo.Select((s, idx) => String.Format("{0} {1}", s.PropertyName, s.SortOrder == SortOrder.Ascending ? "ASC" : "DESC")));

                source = source.OrderBy(orderings);
            }

            return(source.Skip(PagingExtensions.GetSkipCount(paging)).Take(paging.RecordsPerPage));
        }