//MvcHtmlString dönüş türümüzdür
        //this HtmlHelper html neyi extension edeceksek onu yazdık
        //Sayfa bilgilerinede ihtiyacımız var kaç eleman var gibi oda PageningInfo'da bulunuyor
        public static MvcHtmlString Pager(this HtmlHelper html, PageingInfo pageingInfo)
        {
            //sayfa sayısı bulcaz: toplam eleman sayısı bölü her sayfada olacak eleman sayısı
            int totalPage = (int)Math.Ceiling((decimal)pageingInfo.TotalItems / pageingInfo.ItemsPerpage); //yuvarlama yaptık

            var stringBuilder = new StringBuilder();                                                       //her birini bir araya getir

            for (int i = 1; i <= totalPage; i++)
            {
                var tagBuilder = new TagBuilder("a"); //a tag'ini oluştur dedik.
                tagBuilder.MergeAttribute("href", string.Format("/Product/Index/?page={0}&category={1}", i, pageingInfo.CurrentCategory));

                //her döndüğün link oluşturacak
                tagBuilder.InnerHtml = i.ToString(); //a tag'inin içindeki sayıyı verdik
                if (pageingInfo.CurrentPage == i)
                {
                    tagBuilder.AddCssClass("selected");
                }
                else
                {
                    tagBuilder.AddCssClass("btn");
                }
                stringBuilder.Append(tagBuilder); //hepsini bir araya getir
            }

            return(MvcHtmlString.Create(stringBuilder.ToString()));
        }
Exemple #2
0
        public string GetPaginationInfo(PageingInfo paginationInfoSelector)
        {
            lock (_lock)
            {
                switch (paginationInfoSelector)
                {
                case PageingInfo.CurrentAndTotalPage:
                    return(string.Format("{0} / {1}", this.CurrentPage.ToString(), this.TotalPages.ToString()));

                case PageingInfo.TotalRecords:
                    return(string.Format("{0}", this.TotalRecords.ToString()));

                case PageingInfo.CurrentPage:
                    return(string.Format("{0}", this.CurrentPage.ToString()));

                case PageingInfo.FromRecord:
                    return(string.Format("{0}", this.FromRecord.ToString()));

                case PageingInfo.ToRecord:
                    return(string.Format("{0}", this.ToRecord.ToString()));

                case PageingInfo.FromToRecord:
                    return(string.Format("{0} / {1}", this.FromRecord.ToString(), this.ToRecord.ToString()));

                case PageingInfo.FromRecordPageToRecord:
                    return(string.Format("{0} - {1} - {2}", this.FromRecord.ToString(), this.CurrentPage.ToString(), this.ToRecord.ToString()));

                default:
                    throw new ArgumentException("You have to use correct selector.");
                }
            }
        }
        public async Task <ActionResult> GetLeaveOffice([FromQuery] PageingInfo pageingInfo, int jobId)
        {
            int count = 0;

            responseInfo.success = await Task.Factory.StartNew(() => _leaveOfficeService.GetLeaveOffices(pageingInfo.pageIndex, pageingInfo.pageSize, jobId, ref count));

            responseInfo.totalCount = count;
            return(Ok(responseInfo));
        }
Exemple #4
0
        public ViewResult List(string category, int page = 1)
        {
            var Productresult = productRepository.Products.OrderBy(p => p.ProductID).
                                Where(p => category == null || p.Category == category).Skip((page - 1) * pagesize).Take(pagesize);
            var pageinfo = new PageingInfo()
            {
                currentPage = page,
                itemPerPage = pagesize,
                Totalitem   = category == null?productRepository.Products.Count() : productRepository.Products.Count(p => p.Category == category),
            };
            var result = new ProductListViewModel()
            {
                PageingInfo     = pageinfo,
                Products        = Productresult,
                CurrentCategory = category
            };

            return(View(result));
        }
Exemple #5
0
        public static MvcHtmlString PageLinks(this HtmlHelper htmlHelper, PageingInfo pageingInfo,
                                              Func <int, string> pageUrlFunc)
        {
            StringBuilder result = new StringBuilder();

            for (int i = 1; i < pageingInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrlFunc(i));
                tag.InnerHtml = i.ToString();
                if (i == pageingInfo.currentPage)
                {
                    tag.AddCssClass("selected");
                    tag.AddCssClass("btn-primary");
                }
                tag.AddCssClass("btn btn-default");
                result.Append(tag.ToString());
            }
            return(MvcHtmlString.Create(result.ToString()));
        }
        public static MvcHtmlString Pager(this HtmlHelper html, PageingInfo pagingInfo)
        {
            //sayfa sayıyısını bulduk
            int totalPage = (int)Math.Ceiling((decimal)pagingInfo.TotalItems / pagingInfo.ItemsPerPage);


            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 1; i <= totalPage; i++)
            {
                var tagBuilder = new TagBuilder("a");
                tagBuilder.MergeAttribute("href", String.Format("/Product/Index/?page={0}&category={1}", i, pagingInfo.CurrentCategory));
                tagBuilder.InnerHtml = i.ToString();

                if (pagingInfo.CurrentPage == i)
                {
                    tagBuilder.AddCssClass("selected");
                }

                stringBuilder.Append(tagBuilder);
            }

            return(MvcHtmlString.Create(stringBuilder.ToString()));
        }