Ejemplo n.º 1
0
        public static SearchResult <T> Build(
            IEnumerable <T> items,
            PagingData pagingData)
        {
            if (pagingData == null)
            {
                throw new ArgumentNullException(nameof(pagingData));
            }
            var itemsValue = items?.ToArray() ?? throw new ArgumentNullException(nameof(items));

            return(new SearchResult <T>
            {
                Items = itemsValue,
                PagingData = pagingData
            });
        }
Ejemplo n.º 2
0
        public static PagingData MakeForResultCount(PagingData queryPagingData, int resultCount)
        {
            if (queryPagingData == null)
            {
                throw new ArgumentNullException(nameof(queryPagingData));
            }
            if (resultCount < 0)
            {
                throw new ArgumentException("Result count must not be less than zero", nameof(resultCount));
            }

            if (resultCount > queryPagingData.Skip)
            {
                return(new PagingData(queryPagingData.Page, queryPagingData.PageSize, resultCount));
            }

            var maxPage = resultCount <= queryPagingData.PageSize
                ? 1
                : resultCount / queryPagingData.PageSize + 1;

            return(new PagingData(maxPage, queryPagingData.PageSize, resultCount));
        }
Ejemplo n.º 3
0
 public SearchResult(IEnumerable <T> items, PagingData pagingData)
 {
     Items      = items?.ToArray() ?? throw new ArgumentNullException(nameof(items));
     PagingData = pagingData ?? throw new ArgumentNullException(nameof(pagingData));
 }