ContentPagedList.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » MvcHelper » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » MvcHelper » ContentPagedList.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Everest.CmsServices.MvcHelper{
    /// <summary>
    /// 
    /// </summary>
    public class ContentPagedList : List<IDictionary<string, object>>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ContentPagedList"/> class.
        /// </summary>
        /// <param name="contents">The contents.</param>
        /// <param name="totalItemCount">The total item count.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="pageIndex">Index of the page.</param>
        public ContentPagedList(IEnumerable<IDictionary<string, object>> contents, int totalItemCount, int pageSize, int pageIndex)
        {
            Initialize(contents, pageIndex, pageSize, totalItemCount);
        }
        /// <summary>
        /// Gets or sets the page count.
        /// </summary>
        /// <value>The page count.</value>
        public int TotalPages { get; private set; }
        /// <summary>
        /// Gets or sets the total item count.
        /// </summary>
        /// <value>The total item count.</value>
        public int TotalItemCount { get; private set; }
        /// <summary>
        /// Gets or sets the index of the page.
        /// </summary>
        /// <value>The index of the page.</value>
        public int PageIndex { get; private set; }
        /// <summary>
        /// Gets or sets the size of the page.
        /// </summary>
        /// <value>The size of the page.</value>
        public int PageSize { get; private set; }
        /// <summary>
        /// Gets or sets the start index of the next.
        /// </summary>
        /// <value>The start index of the next.</value>
        public int NextStartRowIndex { get; private set; }
        /// <summary>
        /// Gets or sets a value indicating whether this instance has previous page.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance has previous page; otherwise, <c>false</c>.
        /// </value>
        public bool HasPreviousPage { get; private set; }
        /// <summary>
        /// Gets or sets a value indicating whether this instance has next page.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance has next page; otherwise, <c>false</c>.
        /// </value>
        public bool HasNextPage { get; private set; }
        /// <summary>
        /// Gets or sets a value indicating whether this instance is first page.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is first page; otherwise, <c>false</c>.
        /// </value>
        public bool IsFirstPage { get; private set; }
        /// <summary>
        /// Gets or sets a value indicating whether this instance is last page.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is last page; otherwise, <c>false</c>.
        /// </value>
        public bool IsLastPage { get; private set; }

        /// <summary>
        /// Initializes the specified contents.
        /// </summary>
        /// <param name="contents">The contents.</param>
        /// <param name="index">The index.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalCount">The total count.</param>
        protected void Initialize(IEnumerable<IDictionary<string, object>> contents, int index, int pageSize, int totalCount)
        {
            //### argument checking
            if (index < 1)
            {
                index = 1;
            }
            if (pageSize < 1)
            {
                throw new ArgumentOutOfRangeException("PageSize cannot be less than 1.");
            }

            //### set source to blank list if source is null to prevent exceptions
            if (contents != null)
            {
                AddRange(contents);
            }

            TotalItemCount = totalCount;
            PageSize = pageSize;
            PageIndex = index;
            if (TotalItemCount > 0)
            {
                TotalPages = (int)Math.Ceiling(TotalItemCount / (double)PageSize);
            }
            else
            {
                TotalPages = 0;
            }
            HasPreviousPage = (PageIndex - 1 > 0);
            HasNextPage = (PageIndex < TotalPages);
            IsFirstPage = (PageIndex <= 1);
            IsLastPage = (PageIndex >= TotalPages);

            //the next page start row index
            NextStartRowIndex = PageSize * PageIndex;
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.