///<summary> /// Displays a configurable "Go To Page:" form for instances of PagedList. ///</summary> ///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param> ///<param name="list">The PagedList to use as the data source.</param> ///<param name="formAction">The URL this form should submit the GET request to.</param> ///<param name="inputFieldName">The querystring key this form should submit the new page number as.</param> ///<returns>Outputs the "Go To Page:" form HTML.</returns> public static MvcHtmlString PagedListGoToPageForm(this System.Web.Mvc.HtmlHelper html, IPagingInfo list, string formAction, string inputFieldName) { return(PagedListGoToPageForm(html, list, formAction, new GoToFormRenderOptions(inputFieldName))); }
public async Task <PagedCollection <TEntity> > ListAsync(IPagingInfo pagingInfo, Expression <Func <TEntity, bool> > filter, Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy, params string[] includeExpressions) { IQueryable <TEntity> queryBeforePaging = dbSet; if (filter != null) { queryBeforePaging = queryBeforePaging.Where(filter); } foreach (var include in includeExpressions.Where(s => !string.IsNullOrEmpty(s))) { queryBeforePaging = queryBeforePaging.Include(include); } var count = await queryBeforePaging.CountAsync(); if (orderBy != null) { queryBeforePaging = orderBy(queryBeforePaging); } else { queryBeforePaging = queryBeforePaging.OrderBy(h => h.Id); } return(PagedCollection <TEntity> .Create(queryBeforePaging, pagingInfo.PageNumber, pagingInfo.PageSize)); }
///<summary> /// Displays a configurable "Go To Page:" form for instances of PagedList. ///</summary> ///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param> ///<param name="list">The PagedList to use as the data source.</param> ///<param name="formAction">The URL this form should submit the GET request to.</param> ///<param name="options">Formatting options.</param> ///<returns>Outputs the "Go To Page:" form HTML.</returns> public static MvcHtmlString PagedListGoToPageForm(this System.Web.Mvc.HtmlHelper html, IPagingInfo list, string formAction, GoToFormRenderOptions options) { var form = new TagBuilder("form"); form.AddCssClass("PagedList-goToPage"); form.Attributes.Add("action", formAction); form.Attributes.Add("method", "get"); var fieldset = new TagBuilder("fieldset"); var label = new TagBuilder("label"); label.Attributes.Add("for", options.InputFieldName); label.SetInnerText(options.LabelFormat); var input = new TagBuilder("input"); input.Attributes.Add("type", options.InputFieldType); input.Attributes.Add("name", options.InputFieldName); input.Attributes.Add("value", list.PageNumber.ToString()); var submit = new TagBuilder("input"); submit.Attributes.Add("type", "submit"); submit.Attributes.Add("value", options.SubmitButtonFormat); fieldset.InnerHtml = label.ToString(); fieldset.InnerHtml += input.ToString(TagRenderMode.SelfClosing); fieldset.InnerHtml += submit.ToString(TagRenderMode.SelfClosing); form.InnerHtml = fieldset.ToString(); return(new MvcHtmlString(form.ToString())); }
public PagedCollection <TEntity> List <TProperty>(IPagingInfo pagingInfo, Expression <Func <TEntity, bool> > filter, Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy, Expression <Func <TEntity, TProperty> > includeExpressions) { IQueryable <TEntity> queryBeforePaging = dbSet; if (filter != null) { queryBeforePaging = queryBeforePaging.Where(filter); } queryBeforePaging = queryBeforePaging.Include(includeExpressions); var count = queryBeforePaging.Count(); if (orderBy != null) { queryBeforePaging = orderBy(queryBeforePaging); } else { queryBeforePaging = queryBeforePaging.OrderBy(h => h.Id); } return(PagedCollection <TEntity> .Create(queryBeforePaging, pagingInfo.PageNumber, pagingInfo.PageSize)); }
public MessagesController(MaildbContext context, IMessageControl msgCntrl, IAdvancedSearch advSearch, IPagingInfo pageInfo) { _context = context; _msgCntrl = msgCntrl; _advSearch = advSearch; _pageInfo = pageInfo; }
private static TagBuilder ItemSliceAndTotalText(IPagingInfo list, PagedListRenderOptions options) { var text = new TagBuilder("a"); text.SetInnerText(string.Format(options.ItemSliceAndTotalFormat, list.FirstItemOnPage, list.LastItemOnPage, list.TotalItemCount)); return(WrapInListItem(text, options, "PagedList-pageCountAndLocation", "disabled")); }
private static TagBuilder PageCountAndLocationText(IPagingInfo list, PagedListRenderOptions options) { var text = new TagBuilder("a"); text.SetInnerText(string.Format(options.PageCountAndCurrentLocationFormat, list.PageNumber, list.PageCount)); return(WrapInListItem(text, options, "PagedList-pageCountAndLocation", "disabled")); }
public SearchLegalPartyDomain(ISearchProviderSelector searchProviderSelector, ILogger logger, IPagingInfo pagingInfo, ISearchResultsConfiguration searchResultsConfiguration) { _searchProviderSelector = searchProviderSelector; _logger = logger; _pagingInfo = (PagingInfo)pagingInfo; _searchResultsConfiguration = searchResultsConfiguration; }
public ContainsSearchLegalPartyRepository(SearchLegalPartyContext context, IPagingInfo pagingInfo, ILogger logger, ICommandTimeoutConfiguration commandTimeoutConfiguration) { _pagingInfo = (PagingInfo)pagingInfo; _logger = logger; _context = context; _context.Database.SetCommandTimeout(commandTimeoutConfiguration.CommandTimeout); }
/// <summary> /// Adds @PageNumber and @PageSize parameters using the supplied filter. /// </summary> /// <param name="args">The arguments.</param> /// <param name="filter">The filter.</param> public static void AddPagingFilters([NotNull] this DynamicParameters args, [NotNull] IPagingInfo filter) { Contract.Requires(args != null); Contract.Requires(filter != null); args.Add(PageNumber, filter.PageNumber); args.Add(PageSize, filter.PageSize); }
public GameController(IGameRepository repo, IPagingInfo pagInfo, IGamesListViewModel gamlist) { repository = repo; paginatInfo = pagInfo; gamesList = gamlist; paginatInfo.ItemsPerPage = pageSize; paginatInfo.TotalItems = repository.Games.Count(); gamesList.PagingInfo = paginatInfo as IPagingInfo; }
/// <summary> /// Initializes a new instance of the <see cref="PagedResult{T}" /> class. /// </summary> /// <param name="paging">The paging.</param> public PagedResult(IPagingInfo paging) { if (paging == null) { return; } this.CurrentPageNumber = paging.PageNumber; this.PageSize = paging.PageSize; }
public SimpleQuery Page(IPagingInfo paging = null) { this.paging = string.Empty; if (paging != null) { this.paging = paging.ToQueryString(); } ; return(this); }
public async Task <IEnumerable <JourneyViewModel> > GetAllAsync( string company, string country, DateTime?dateFrom, DateTime?dateTo, ISortingInfo sortingInfo, IPagingInfo pagingInfo) { var query = BuildIndexQuery(company, country, dateFrom, dateTo, sortingInfo, true, pagingInfo); var data = await query.Select(v => _mapper.Map <Journey, JourneyViewModel>(v)).ToListAsync(); return(data); }
public ActionResult Pagination(IPagingInfo pagingInfo) { var pagination = new Pagination { CurrentPage = 1, PageNumbers = Enumerable.Range(1, 2).ToArray(), PageSize = 5, TotalRecords = 6, TotalPages = 2, ShowingFrom = 1, ShowingTo = 5 }; return(Display(pagination)); }
private static TagBuilder First(IPagingInfo list, Func <int, string> generatePageUrl, PagedListRenderOptions options) { const int targetPageNumber = 1; var first = new TagBuilder("a") { InnerHtml = string.Format(options.LinkToFirstPageFormat, targetPageNumber) }; if (list.IsFirstPage) { return(WrapInListItem(first, options, "PagedList-skipToFirst", "disabled")); } first.Attributes["href"] = generatePageUrl(targetPageNumber); return(WrapInListItem(first, options, "PagedList-skipToFirst")); }
private static TagBuilder Page(int i, IPagingInfo list, Func <int, string> generatePageUrl, PagedListRenderOptions options) { var format = options.FunctionToDisplayEachPageNumber ?? (pageNumber => string.Format(options.LinkToIndividualPageFormat, pageNumber)); var targetPageNumber = i; var page = new TagBuilder("a"); page.SetInnerText(format(targetPageNumber)); if (i == list.PageNumber + 1) { return(WrapInListItem(page, options, "active")); } page.Attributes["href"] = generatePageUrl(targetPageNumber); return(WrapInListItem(page, options)); }
/// <summary> /// 按Query条件查询并返回支持分页的对象列表 /// </summary> /// <param name="query">查询条件</param> /// <param name="pagingInfo">分页信息</param> /// <param name="orderBy">排序字段信息</param> /// <returns>支持翻页的对象列表</returns> public virtual IPagedList <T> GetObjectPagedList(IQueryOver <T, T> query, IPagingInfo pagingInfo, OrderField orderBy) { bool needPaging = pagingInfo != null && pagingInfo.IsLegal; if (needPaging) { if (pagingInfo.DoCount) { pagingInfo.RecordCount = query.RowCountInt64(); } query.Skip((pagingInfo.CurrentPage - 1) * pagingInfo.PageSize).Take(pagingInfo.PageSize); } query.RootCriteria.AddOrder(new Order(orderBy.PropertyName, orderBy.Ascending)); IList <T> list = query.List <T>(); return(needPaging ? list.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize, (int)pagingInfo.RecordCount) : list.ToPagedList(1, list.Count)); }
private static TagBuilder Next(IPagingInfo list, Func <int, string> generatePageUrl, PagedListRenderOptions options) { var targetPageNumber = list.PageNumber + 2; var next = new TagBuilder("a") { InnerHtml = string.Format(options.LinkToNextPageFormat, targetPageNumber) }; next.Attributes["rel"] = "next"; if (!list.HasNextPage) { return(WrapInListItem(next, options, "PagedList-skipToNext", "disabled")); } next.Attributes["href"] = generatePageUrl(targetPageNumber); return(WrapInListItem(next, options, "PagedList-skipToNext")); }
private static TagBuilder Previous(IPagingInfo list, Func <int, string> generatePageUrl, PagedListRenderOptions options) { var targetPageNumber = list.PageNumber; //- 1; var previous = new TagBuilder("a") { InnerHtml = string.Format(options.LinkToPreviousPageFormat, targetPageNumber) }; previous.Attributes["rel"] = "prev"; if (!list.HasPreviousPage) { return(WrapInListItem(previous, options, "PagedList-skipToPrevious", "disabled")); } previous.Attributes["href"] = generatePageUrl(targetPageNumber); return(WrapInListItem(previous, options, "PagedList-skipToPrevious")); }
public async Task <DbRecordList <User> > SearchAsync( string keyword, Sorting <UserSortableFields> sorting = null, IPagingInfo paging = null) { var records = new DbRecordList <User>(paging); // Default sorting if (sorting == null) { sorting = new Sorting <UserSortableFields>(UserSortableFields.FirstName, SortDirection.Asc); } var param = new DynamicParameters(); string filter = GetSqlFilter(keyword, param); var query = new SimpleQuery(GetBaseQuery()) .SetFilter(filter) .SortBy(sorting) .Page(paging); var record = await DbClient.QueryAsync <User, Company, User>( query.ToString(), (user, company) => { user.CompanyInfo = company; return(user); }, param); if (record == null) { return(records); } records.Records = record; records.TotalCount = await GetTotalCountAsync(filter, param, "u"); return(records); }
/// <summary> /// Returns a paged collection of entities, optionally filtered and sorted with specified associated entities eagerly loaded. /// </summary> /// <param name="pagingInfo">The paging information.</param> /// <param name="filter">The filter.</param> /// <param name="orderBy">The order by.</param> /// <param name="relatedEntitiesToEagerlyLoad">Names of properties representing related entities to be eagerly loaded.</param> /// <returns></returns> public IPagedCollection <TEntity> List(IPagingInfo pagingInfo, Expression <Func <TEntity, bool> > filter, Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy, params string[] relatedEntitiesToEagerlyLoad) { IQueryable <TEntity> query = dbSet; ICollection <TEntity> data; if (filter != null) { query = query.Where(filter); } foreach (var relatedEntityToEagerlyLoad in relatedEntitiesToEagerlyLoad) { query.Include(relatedEntityToEagerlyLoad); } var count = query.Count(); if (orderBy != null) { data = orderBy(query) .Skip(pagingInfo.FirstResult) .Take(pagingInfo.MaxResults) .ToList(); } else { data = query.OrderBy(h => h.Id) .Skip(pagingInfo.FirstResult) .Take(pagingInfo.MaxResults) .ToList(); } return(new PagedCollection <TEntity> { TotalRowCount = count, Data = data }); }
public static MvcHtmlString PageLinks(this HtmlHelper html, IPagingInfo pagingInfo, Func <int, string> pageUrl) { StringBuilder result = new StringBuilder(); for (int i = 1; i <= pagingInfo.TotalPages; i++) { TagBuilder tag = new TagBuilder("a"); tag.MergeAttribute("href", pageUrl(i)); tag.InnerHtml = i.ToString(); if (i == pagingInfo.CurrentPage) { tag.AddCssClass("selected"); tag.AddCssClass("btn-primary"); } tag.AddCssClass("btn btn-default"); result.Append(tag.ToString()); } return(MvcHtmlString.Create(result.ToString())); }
/// <summary> /// 根据过滤条件查询并返回支持翻页的对象列表 /// </summary> /// <param name="pagingInfo">分页信息</param> /// <param name="orderBy">排序字段信息</param> /// <param name="condition">过滤条件</param> /// <returns>带有翻页信息的对象列表</returns> public virtual IPagedList <T> GetObjectPagedList(IPagingInfo pagingInfo, OrderField orderBy, Expression <Func <T, bool> > condition = null) { var query = this.CreateQueryOver(); if (condition != null) { query.Where(condition); } bool needPaging = pagingInfo != null && pagingInfo.IsLegal; if (needPaging) { if (pagingInfo.DoCount) { pagingInfo.RecordCount = query.RowCountInt64(); } query.Skip((pagingInfo.CurrentPage - 1) * pagingInfo.PageSize).Take(pagingInfo.PageSize); } query.RootCriteria.AddOrder(new Order(orderBy.PropertyName, orderBy.Ascending)); IList <T> list = query.List <T>(); return(needPaging ? list.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize, (int)pagingInfo.RecordCount) : list.ToPagedList(1, list.Count)); }
public static IQueryable <T> SkipToPage <T>([CanBeNull] this IQueryable <T> list, [CanBeNull] IPagingInfo pagingInfo) { if (list == null) { return(Enumerable.Empty <T>().AsQueryable()); } if (pagingInfo == null) { pagingInfo = new PagingInfo(); } return(list.Skip(Convert.ToInt32((pagingInfo.PageNumber - 1) * pagingInfo.PageSize)).Take(Convert.ToInt32(pagingInfo.PageSize))); }
/// <summary> /// 分页返回结果 /// </summary> public PagingResult(IList <TData> data, int totalCount, IPagingInfo pager) : this(data, totalCount, pager?.PageIndex ?? 0, pager?.PageSize ?? 0) { }
///<summary> /// Displays a configurable paging control for instances of PagedList. ///</summary> ///<param name = "html">This method is meant to hook off HtmlHelper as an extension method.</param> ///<param name = "list">The PagedList to use as the data source.</param> ///<param name = "generatePageUrl">A function that takes the page number of the desired page and returns a URL-string that will load that page.</param> ///<returns>Outputs the paging control HTML.</returns> public static MvcHtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html, IPagingInfo list, Func <int, string> generatePageUrl) { return(PagedListPager(html, list, generatePageUrl, new PagedListRenderOptions())); }
///<summary> /// Displays a configurable paging control for instances of PagedList. ///</summary> ///<param name = "html">This method is meant to hook off HtmlHelper as an extension method.</param> ///<param name = "list">The PagedList to use as the data source.</param> ///<param name = "generatePageUrl">A function that takes the page number of the desired page and returns a URL-string that will load that page.</param> ///<param name = "options">Formatting options.</param> ///<returns>Outputs the paging control HTML.</returns> public static MvcHtmlString PagedListPager(this System.Web.Mvc.HtmlHelper html, IPagingInfo list, Func <int, string> generatePageUrl, PagedListRenderOptions options) { if (options.Display == PagedListDisplayMode.Never || (options.Display == PagedListDisplayMode.IfNeeded && list.PageCount <= 1)) { return(null); } var listItemLinks = new List <TagBuilder>(); //calculate start and end of range of page numbers var firstPageToDisplay = 1; var lastPageToDisplay = list.PageCount; var pageNumbersToDisplay = lastPageToDisplay; if (options.MaximumPageNumbersToDisplay.HasValue && list.PageCount > options.MaximumPageNumbersToDisplay) { // cannot fit all pages into pager var maxPageNumbersToDisplay = options.MaximumPageNumbersToDisplay.Value; firstPageToDisplay = list.PageNumber - maxPageNumbersToDisplay / 2; if (firstPageToDisplay < 1) { firstPageToDisplay = 1; } pageNumbersToDisplay = maxPageNumbersToDisplay; lastPageToDisplay = firstPageToDisplay + pageNumbersToDisplay - 1; if (lastPageToDisplay > list.PageCount) { firstPageToDisplay = list.PageCount - maxPageNumbersToDisplay + 1; } } //first if (options.DisplayLinkToFirstPage == PagedListDisplayMode.Always || (options.DisplayLinkToFirstPage == PagedListDisplayMode.IfNeeded && firstPageToDisplay > 1)) { listItemLinks.Add(First(list, generatePageUrl, options)); } //previous if (options.DisplayLinkToPreviousPage == PagedListDisplayMode.Always || (options.DisplayLinkToPreviousPage == PagedListDisplayMode.IfNeeded && !list.IsFirstPage)) { listItemLinks.Add(Previous(list, generatePageUrl, options)); } //text if (options.DisplayPageCountAndCurrentLocation) { listItemLinks.Add(PageCountAndLocationText(list, options)); } //text if (options.DisplayItemSliceAndTotal) { listItemLinks.Add(ItemSliceAndTotalText(list, options)); } //page if (options.DisplayLinkToIndividualPages) { //if there are previous page numbers not displayed, show an ellipsis if (options.DisplayEllipsesWhenNotShowingAllPageNumbers && firstPageToDisplay > 1) { listItemLinks.Add(Ellipses(options)); } foreach (var i in Enumerable.Range(firstPageToDisplay, pageNumbersToDisplay)) { //show delimiter between page numbers if (i > firstPageToDisplay && !string.IsNullOrWhiteSpace(options.DelimiterBetweenPageNumbers)) { listItemLinks.Add(WrapInListItem(options.DelimiterBetweenPageNumbers)); } //show page number link listItemLinks.Add(Page(i, list, generatePageUrl, options)); } //if there are subsequent page numbers not displayed, show an ellipsis if (options.DisplayEllipsesWhenNotShowingAllPageNumbers && (firstPageToDisplay + pageNumbersToDisplay - 1) < list.PageCount) { listItemLinks.Add(Ellipses(options)); } } //next if (options.DisplayLinkToNextPage == PagedListDisplayMode.Always || (options.DisplayLinkToNextPage == PagedListDisplayMode.IfNeeded && !list.IsLastPage)) { listItemLinks.Add(Next(list, generatePageUrl, options)); } //last if (options.DisplayLinkToLastPage == PagedListDisplayMode.Always || (options.DisplayLinkToLastPage == PagedListDisplayMode.IfNeeded && lastPageToDisplay < list.PageCount)) { listItemLinks.Add(Last(list, generatePageUrl, options)); } if (listItemLinks.Any()) { //append class to first item in list? if (!string.IsNullOrWhiteSpace(options.ClassToApplyToFirstListItemInPager)) { listItemLinks.First().AddCssClass(options.ClassToApplyToFirstListItemInPager); } //append class to last item in list? if (!string.IsNullOrWhiteSpace(options.ClassToApplyToLastListItemInPager)) { listItemLinks.Last().AddCssClass(options.ClassToApplyToLastListItemInPager); } //append classes to all list item links foreach (var li in listItemLinks) { foreach (var c in options.LiElementClasses ?? Enumerable.Empty <string>()) { li.AddCssClass(c); } } } //collapse all of the list items into one big string var listItemLinksString = listItemLinks.Aggregate( new StringBuilder(), (sb, listItem) => sb.Append(listItem.ToString()), sb => sb.ToString() ); var ul = new TagBuilder("ul") { InnerHtml = listItemLinksString }; foreach (var c in options.UlElementClasses ?? Enumerable.Empty <string>()) { ul.AddCssClass(c); } var outerDiv = new TagBuilder("div"); foreach (var c in options.ContainerDivClasses ?? Enumerable.Empty <string>()) { outerDiv.AddCssClass(c); } outerDiv.InnerHtml = ul.ToString(); return(new MvcHtmlString(outerDiv.ToString())); }
public DbRecordList(IPagingInfo paging) { Paging = paging; }
///<summary> /// Displays a configurable "Go To Page:" form for instances of PagedList. ///</summary> ///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param> ///<param name="list">The PagedList to use as the data source.</param> ///<param name="formAction">The URL this form should submit the GET request to.</param> ///<returns>Outputs the "Go To Page:" form HTML.</returns> public static MvcHtmlString PagedListGoToPageForm(this System.Web.Mvc.HtmlHelper html, IPagingInfo list, string formAction) { return(PagedListGoToPageForm(html, list, formAction, "page")); }