コード例 #1
0
        public void IterateFromPaginated()
        {
            int        regularPageSize = 10;
            List <int> list            = GetCollection(regularPageSize);
            int        pages           = list.Count / 10;
            int        lastPageSize    = list.Count % 10;

            Assert.NotEqual(0, lastPageSize);

            IPage <int> currentPage;
            List <int>  currentPageList;
            bool        gotAnIncompletePage = false;

            IPaginated <int> paginated = list.Paginate(regularPageSize);

            do
            {
                currentPage     = paginated.GetNext();
                currentPageList = currentPage.ToList();
                if (currentPage.PageIndex == pages)
                {
                    gotAnIncompletePage = true;
                    Assert.Equal(lastPageSize, currentPageList.Count);
                }
                for (int i = 0; i < currentPageList.Count; i++)
                {
                    Assert.Equal(list[i + (currentPage.PageIndex * regularPageSize)], currentPageList[i]);
                }
            } while (currentPage.Any());
            Assert.True(gotAnIncompletePage);
            // we should go one past the number of pages because the index is 0 based
            // we start and end with an empty current page
            Assert.Equal(pages, currentPage.PageIndex - 1);
            Assert.Empty(currentPage);
        }
コード例 #2
0
        internal static HtmlContentBuilder Next <T>(HtmlContentBuilder content, IPaginated <T> paginated, Func <int, string> generatePageUrl, PaginatedOptions options)
        {
            TagBuilder tag = TagLink(paginated.IsLastPage ? "#" : generatePageUrl(paginated.PageNumber + 1), options.NextLabel, options.CssClassAnchor);

            content.AppendHtml(tag, paginated.IsLastPage ? options.CssClassLiDisabled : null);
            return(content);
        }
コード例 #3
0
        internal static IHtmlContent PaginationNumbers <T>(IPaginated <T> paginated, Func <int, string> generatePageUrl, PaginatedOptions options = null)
        {
            if (options == null)
            {
                options = new PaginatedOptions();
            }
            HtmlContentBuilder content = CreateHtmlContentBuilder(options);

            Numbers(content, paginated, generatePageUrl, options);
            content.AppendHtml("</ul>");
            return(content);
        }
コード例 #4
0
 internal PaginatedRestBase(IPaginated <T> source)
 {
     PageCount       = source.PageCount;
     TotalItemCount  = source.TotalItemCount;
     PageNumber      = source.PageNumber;
     PageSize        = source.PageSize;
     HasPreviousPage = source.HasPreviousPage;
     HasNextPage     = source.HasNextPage;
     IsFirstPage     = source.IsFirstPage;
     IsLastPage      = source.IsLastPage;
     FirstItemOnPage = source.FirstItemOnPage;
     LastItemOnPage  = source.LastItemOnPage;
     Items           = source.AsEnumerable();
 }
コード例 #5
0
        internal static IHtmlContent PaginationFirstPreviousNextLast <T>(IPaginated <T> paginated, Func <int, string> generatePageUrl, PaginatedOptions options = null)
        {
            if (options == null)
            {
                options = new PaginatedOptions();
            }
            HtmlContentBuilder content = CreateHtmlContentBuilder(options);

            First(content, paginated, generatePageUrl, options);
            Previous(content, paginated, generatePageUrl, options);
            Next(content, paginated, generatePageUrl, options);
            Last(content, paginated, generatePageUrl, options);
            content.AppendHtml("</ul>");
            return(content);
        }
コード例 #6
0
 public static PaginatedMetaData ToPaginatedMetaData(this IPaginated source)
 {
     return(new PaginatedMetaData(
                source.PageCount,
                source.TotalItemCount,
                source.PageNumber,
                source.PageSize,
                source.HasPreviousPage,
                source.HasNextPage,
                source.IsFirstPage,
                source.IsLastPage,
                source.FirstItemOnPage,
                source.LastItemOnPage,
                source.Pages,
                source.MaximumPageNumbersToDisplay));
 }
コード例 #7
0
        public IViewComponentResult Invoke(IPaginated paginated, int pageLimit)
        {
            var allRouteData = new Dictionary <string, string>(
                Request.Query.Select(kv => new KeyValuePair <string, string>(kv.Key, kv.Value))
                );
            var model = new PaginationViewModel
            {
                CurrentPage     = paginated.CurrentPage,
                HasNextPage     = paginated.HasNextPage,
                HasPreviousPage = paginated.HasPreviousPage,
                FollowingPages  = paginated.GetFollowingPages(pageLimit),
                PreviousPages   = paginated.GetPreviousPages(pageLimit),
                LastPage        = paginated.LastPage,
                AllRouteData    = allRouteData,
            };

            return(View(model));
        }
コード例 #8
0
 internal static HtmlContentBuilder Numbers <T>(HtmlContentBuilder content, IPaginated <T> paginated, Func <int, string> generatePageUrl, PaginatedOptions options)
 {
     if (options.MaximumPageNumbersToDisplay != 8)
     {
         paginated.SetPages(options.MaximumPageNumbersToDisplay);
     }
     paginated
     .Pages
     .ToList()
     .ForEach(x =>
     {
         var tagLink = TagLink((paginated.PageNumber != x) ? generatePageUrl(x) : "#", x.ToString(), options.CssClassAnchor);
         content.AppendHtml(tagLink, (paginated.PageNumber == x)
                ? options.CssClassLiActive + " " + options.CssClassLi
                : options.CssClassLi);
     });
     return(content);
 }
コード例 #9
0
        public bool Equals(IPaginated <T> x, IPaginated <T> y)
        {
            if (x == null)
            {
                return(false);
            }
            if (y == null)
            {
                return(false);
            }

            return(Equals(x.Data.Count, y.Data.Count) &&
                   Equals(x.CurrentPage, y.CurrentPage) &&
                   Equals(x.IsFirstPage, y.IsFirstPage) &&
                   Equals(x.IsLastPage, y.IsLastPage) &&
                   Equals(x.NextPage, y.NextPage) &&
                   Equals(x.PageCount, y.PageCount) &&
                   Equals(x.PageSize, y.PageSize) &&
                   Equals(x.PreviousPage, y.PreviousPage) &&
                   Equals(x.TotalRowsCount, y.TotalRowsCount));
        }
コード例 #10
0
        public static IHtmlContent Pagination <T>(this IHtmlHelper htmlHelper, IPaginated <T> paginated, Func <int, string> generatePageUrl, PaginatedStyle paginatedStyle = PaginatedStyle.NumbersWithFirstPreviousNextLast, PaginatedOptions options = default(PaginatedOptions))
        {
            IHtmlContent content = null;

            switch (paginatedStyle)
            {
            case PaginatedStyle.FirstPreviousNextLast:
            {
                content = PaginationFirstPreviousNextLast(paginated, generatePageUrl, options);
                break;
            }

            case PaginatedStyle.Numbers:
            {
                content = PaginationNumbers(paginated, generatePageUrl, options);
                break;
            }

            case PaginatedStyle.NumbersWithFirstPreviousNextLast:
            {
                content = PaginationNumbersWithFirstPreviousNextLast(paginated, generatePageUrl, options);
                break;
            }

            case PaginatedStyle.NumbersWithPreviousNext:
            {
                content = PaginationNumbersWithPreviousNext(paginated, generatePageUrl, options);
                break;
            }

            case PaginatedStyle.PreviousNext:
            {
                content = PaginationPreviousNext(paginated, generatePageUrl, options);
                break;
            }
            }
            return(content);
        }
コード例 #11
0
 public static IPaginated <T> ToPaginatedDto <T, TEntity>(this IPaginated <TEntity> source, Func <TEntity, T> selector)
 {
     return(new Paginated <T>(source.PageIndex, source.PageSize, source.TotalCount, source.Items.Select(selector)));
 }
コード例 #12
0
 public static IPaginated <T> ToPaginatedDto <T, TEntity>(this IPaginated <TEntity> source, IEnumerable <T> items)
 {
     return(new Paginated <T>(source.PageIndex, source.PageSize, source.TotalCount, items));
 }
コード例 #13
0
 public int GetHashCode(IPaginated <T> obj)
 {
     throw new System.NotImplementedException();
 }
コード例 #14
0
        public static string Counter(IPaginated paginated, int counter)
        {
            var index = (paginated.CurrentPage - 1) * paginated.PageSize + counter;

            return(index.ToPersianNumbers());
        }
コード例 #15
0
 public EmployeeController(ICommonRepository <Employee> commonRepository, IPaginated <Employee> paginatedQueryRepository)
 {
     employeeRepository = commonRepository;
     paginatedQueryRepo = paginatedQueryRepository;
 }
コード例 #16
0
 public Cache(IPaginated <T> dataSupplier, int blockSize)
 {
     dataSupply = dataSupplier;
     BlockSize  = blockSize;
     LoadFirstTwoPages();
 }
コード例 #17
0
ファイル: PageBase.cs プロジェクト: mrlunchbox777/StandardDot
 /// <param name="source">The subset that the page represents</param>
 /// <param name="parentCollection">The enumerable that the subset came from</param>
 /// <param name="pageIndex">The index of the subset</param>
 public PageBase(IEnumerable <T> source, IPaginated <T> parentCollection, int pageIndex)
 {
     Source           = source;
     ParentCollection = parentCollection;
     PageIndex        = pageIndex;
 }
コード例 #18
0
 /// <param name="source">The subset that the page represents</param>
 /// <param name="parentCollection">The enumerable that the subset came from</param>
 /// <param name="pageIndex">The index of the subset</param>
 public Page(IEnumerable <T> source, IPaginated <T> parentCollection, int pageIndex)
     : base(source, parentCollection, pageIndex)
 {
 }
コード例 #19
0
 internal PaginatedRest(IPaginated <T> source)
     : base(source)
 {
 }