Exemplo n.º 1
0
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            var old = bindingContext.Model as ListPagination;

            var result = old;

            if (value.FirstValue.HasValue())
            {
                result = new ListPagination(old?.Container, value.FirstValue)
                {
                    Prefix = old.Prefix,
                };

                if (old != null)
                {
                    result.UseAjaxPost = old.UseAjaxPost;
                    result.UseAjaxGet  = old.UseAjaxGet;
                }
            }

            bindingContext.Result = ModelBindingResult.Success(result);

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            var prefix = bindingContext.ModelName.OrEmpty().Unless("p");

            if (prefix.EndsWith(".p"))
            {
                prefix = prefix.Split('.').ExceptLast().ToString(".");
            }

            var old = bindingContext.Model as ListPagination;

            var result = old;

            if (value.FirstValue.HasValue())
            {
                result = new ListPagination(old?.Container, value.FirstValue);
                if (old != null)
                {
                    result.UseAjaxPost = old.UseAjaxPost;
                    result.UseAjaxGet  = old.UseAjaxGet;
                }
            }

            bindingContext.Result = ModelBindingResult.Success(result);

            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
 public PaginationRenderer(IHtmlHelper html, ListPagination paging, int visiblePages, object htmlAttributes, string prefix)
 {
     Html           = html;
     Paging         = paging;
     VisiblePages   = visiblePages;
     HtmlAttributes = htmlAttributes;
     Prefix         = prefix;
 }
Exemplo n.º 4
0
        public static IEnumerable <T> TakePage <T>(this IEnumerable <T> list, ListPagination paging)
        {
            if (paging.PageSize == null)
            {
                return(list);
            }

            var pageSize    = paging.PageSize.Value;
            var currentPage = paging.CurrentPage.LimitMin(1);

            var skip = pageSize * (currentPage - 1);

            if (currentPage > 1 && skip > list.Count())
            {
                skip = 0;
            }

            return(list.Take(skip, pageSize));
        }
Exemplo n.º 5
0
 public static IEnumerable <T> TakePage <T>(this IEnumerable <T> list, ListPagination paging) =>
 list.TakePage(paging.PageSize, paging.CurrentPage);
Exemplo n.º 6
0
 public static T Page <T>(this T query, ListPagination paging)
     where T : IDatabaseQuery
 {
     query.Page(paging.CurrentPage, paging.PageSize ?? 100000);
     return(query);
 }
Exemplo n.º 7
0
 public static HtmlString Pagination(this IHtmlHelper html, ListPagination paging, int visiblePages, object htmlAttributes = null, string prefix = null) =>
 new PaginationRenderer(html, paging, visiblePages, htmlAttributes, prefix).Render();
Exemplo n.º 8
0
 public static HtmlString Pagination(this IHtmlHelper html, ListPagination paging, object htmlAttributes = null, string prefix = null) =>
 Pagination(html, paging, DEFAULT_VISIBLE_PAGES, htmlAttributes, prefix);
Exemplo n.º 9
0
 public static T Page <T>(this T query, ListPagination paging)
     where T : IDatabaseQuery
 {
     query.Page((paging.CurrentPage - 1) * paging.PageSize ?? DEFATLT_PAGE_SIZE, paging.PageSize ?? DEFATLT_PAGE_SIZE);
     return(query);
 }