Ejemplo n.º 1
0
        public MvcHtmlString GalleryWithAloneImagesPaging()
        {
            var galleryCount        = Math.Ceiling(_galleryService.Counter(_gallerySettings.ItemPerPage < 1 ? 1 : _gallerySettings.ItemPerPage));
            var countWithoutGallery = Math.Ceiling(_galleryService.ImagesWithoutGalleryCounter(_gallerySettings.ItemPerPage < 1 ? 1 : _gallerySettings.ItemPerPage));
            var count = galleryCount + countWithoutGallery - 1;

            if (Request.Url == null)
            {
                throw new ArgumentNullException("request url is null");
            }

            var urlNow         = Request.Url.ToString();
            var posQueryString = urlNow.IndexOf('?');

            if (posQueryString >= 0)
            {
                urlNow = urlNow.Remove(posQueryString);
            }
            var page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"]) : 1;

            if (count > 1)
            {
                var sb = new StringBuilder();
                sb.Append(@"<div class=""pagination pagination-centered""><ul>");
                if (page >= 4)
                {
                    sb.Append(@"<li><a href=""");
                    sb.Append(String.Format("{0}?page={1}", urlNow, 1));
                    sb.Append(@""">");
                    sb.Append(_localizationService.GetResource("Plugin.Widgets.Gallery.Pager.First"));
                    sb.Append("</a></li>");
                }

                if (page != 1)
                {
                    sb.Append(@"<li><a href=""");
                    sb.Append(String.Format("{0}?page={1}", urlNow, page - 1));
                    sb.Append(@""">");
                    sb.Append(_localizationService.GetResource("Plugin.Widgets.Gallery.Pager.Previous"));
                    sb.Append("</a></li>");
                }

                if (page < 4)
                {
                    if (count < 5)
                    {
                        for (var i = 1; i <= count; i++)
                        {
                            sb.Append(@"<li><a href=""");
                            sb.Append(String.Format("{0}?page={1}", urlNow, i));
                            sb.Append(@""">");
                            sb.Append(i);
                            sb.Append("</a></li>");
                        }
                    }
                    else
                    {
                        for (var i = 1; i <= 5; i++)
                        {
                            sb.Append(@"<li><a href=""");
                            sb.Append(String.Format("{0}?page={1}", urlNow, i));
                            sb.Append(@""">");
                            sb.Append(i);
                            sb.Append("</a></li>");
                        }
                    }
                }

                if (page >= 4 && page + 2 < count)
                {
                    for (var i = (page - 2); i <= (page + 2); i++)
                    {
                        sb.Append(@"<li><a href=""");
                        sb.Append(String.Format("{0}?page={1}", urlNow, i));
                        sb.Append(@""">");
                        sb.Append(i);
                        sb.Append("</a></li>");
                    }
                }

                if (page >= 4 && page + 2 >= count)
                {
                    if (page == 4)
                    {
                        for (var i = 2; i <= count; i++)
                        {
                            sb.Append(@"<li><a href=""");
                            sb.Append(String.Format("{0}?page={1}", urlNow, i));
                            sb.Append(@""">");
                            sb.Append(i);
                            sb.Append("</a></li>");
                        }
                    }
                    else
                    {
                        for (var i = (count - 4); i <= count; i++)
                        {
                            sb.Append(@"<li><a href=""");
                            sb.Append(String.Format("{0}?page={1}", urlNow, i));
                            sb.Append(@""">");
                            sb.Append(i);
                            sb.Append("</a></li>");
                        }
                    }
                }

                if (page != count)
                {
                    sb.Append(@"<li><a href=""");
                    sb.Append(String.Format("{0}?page={1}", urlNow, page + 1));
                    sb.Append(@""">");
                    sb.Append(_localizationService.GetResource("Plugin.Widgets.Gallery.Pager.Next"));
                    sb.Append("</a></li>");
                }
                if (page + 2 < count)
                {
                    sb.Append(@"<li><a href=""");
                    sb.Append(String.Format("{0}?page={1}", urlNow, count));
                    sb.Append(@""">");
                    sb.Append(_localizationService.GetResource("Plugin.Widgets.Gallery.Pager.Last"));
                    sb.Append("</a></li>");
                }

                sb.Append("</ul></div>");
                return(MvcHtmlString.Create(sb.ToString()));
            }

            return(null);
        }