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); }
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); }
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); }
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(); }
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); }
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)); }
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)); }
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); }
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)); }
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); }
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))); }
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)); }
public int GetHashCode(IPaginated <T> obj) { throw new System.NotImplementedException(); }
public static string Counter(IPaginated paginated, int counter) { var index = (paginated.CurrentPage - 1) * paginated.PageSize + counter; return(index.ToPersianNumbers()); }
public EmployeeController(ICommonRepository <Employee> commonRepository, IPaginated <Employee> paginatedQueryRepository) { employeeRepository = commonRepository; paginatedQueryRepo = paginatedQueryRepository; }
public Cache(IPaginated <T> dataSupplier, int blockSize) { dataSupply = dataSupplier; BlockSize = blockSize; LoadFirstTwoPages(); }
/// <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; }
/// <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) { }
internal PaginatedRest(IPaginated <T> source) : base(source) { }