Example #1
0
        public static PaginatedResult <TResult> ToPaginatedResult <TSource, TResult>(
            this IOrderedQueryable <TSource> sourceCollection,
            SelectionParameters <TSource> selectionParameters)
        {
            var paginatedCollection = new PaginatedResult <TResult>();

            if (sourceCollection == null)
            {
                return(paginatedCollection);
            }

            IQueryable <TSource> resultCollection = sourceCollection;

            paginatedCollection.TotalRows = resultCollection.Count();

            if (selectionParameters?.IsPaged == true)
            {
                resultCollection = sourceCollection.ApplyPaging(selectionParameters);
            }

            paginatedCollection.Items = resultCollection.ProjectTo <TResult>().ToList();

            return(paginatedCollection);
        }