PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Packaging/Pager.cs

#
C# | 89 lines | 50 code | 6 blank | 33 comment | 2 complexity | 73576ba53dc0eecc08b9cebb09c89aac MD5 | raw file
 1using System.Collections.Generic;
 2
 3namespace BlogEngine.Core.Packaging
 4{
 5    /// <summary>
 6    /// Gallery pager
 7    /// </summary>
 8    public class Pager
 9    {
10        #region Private members
11        private static int _currentPage;
12        private static int _itemCount;
13        private static string _pkgType;
14        #endregion
15
16        /// <summary>
17        /// Pager
18        /// </summary>
19        /// <param name="currentPage">Current page</param>
20        /// <param name="itemCount">Item count</param>
21        /// <param name="pkgType">Package type</param>
22        public Pager(int currentPage, int itemCount, string pkgType)
23        {
24            _currentPage = currentPage;
25            _itemCount = itemCount;
26            _pkgType = pkgType;
27        }
28
29        /// <summary>
30        /// Current page
31        /// </summary>
32        public int CurrentPage
33        {
34            get { return _currentPage; }
35        }
36
37        /// <summary>
38        /// Pager items
39        /// </summary>
40        public List<PagerItem> PageItems
41        {
42            get
43            {
44                var items = new List<PagerItem>();
45
46                for (int i = 0; i <= (int)(_itemCount / Constants.PageSize); i++)
47                {
48                    items.Add(i == _currentPage ? new PagerItem(i, true, _pkgType) : new PagerItem(i, false, _pkgType));
49                }
50                return items;
51            }
52        }
53    }
54
55    /// <summary>
56    /// Page Item
57    /// </summary>
58    public class PagerItem
59    {
60        private readonly string _pkgType;
61        /// <summary>
62        /// Constructor
63        /// </summary>
64        /// <param name="pageNumber"></param>
65        /// <param name="current"></param>
66        /// <param name="pkgType"></param>
67        public PagerItem(int pageNumber, bool current, string pkgType = "")
68        {
69            PageNumber = pageNumber;
70            Current = current;
71            _pkgType = pkgType;
72        }
73        /// <summary>
74        /// Page number
75        /// </summary>
76        public int PageNumber { get; set; }
77        /// <summary>
78        /// Current selected page
79        /// </summary>
80        public bool Current { get; set; }
81        /// <summary>
82        /// Page link
83        /// </summary>
84        public string PageLink 
85        {
86            get { return string.Format("GalleryGetPackages({0},'{1}'); return false;", PageNumber, _pkgType); }
87        }
88    }
89}