Esempio n. 1
0
 private void RedirectIfSite()
 {
     if (_pageTypeId == 0 && SiteFactory.IsSite(_pageId))
     {
         Response.Redirect(string.Format("EditSite.aspx?id={0}", _pageId));
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            var pageTypes = PageType.PageTypes;

            if (pageTypes == null)
            {
                return;
            }

            bool allowAll;

            Type[] allowedTypes;
            Guid   pageId;

            Guid.TryParse(Request.QueryString["pageId"], out pageId);

            if (SiteFactory.IsSite(pageId))
            {
                allowedTypes = CmsSite.AllowedTypes;
                allowAll     = allowedTypes == null;

                if (allowedTypes != null && allowedTypes.Length == 0)
                {
                    PageTypeList.Text = "No pages can be created under the selected page.";
                    return;
                }
            }
            else
            {
                var parent         = PageFactory.GetPage(pageId);
                var parentPageType = pageTypes.Find(p => p.PageTypeId == parent.PageTypeId);
                allowedTypes = parentPageType.AllowedTypes;
                allowAll     = parentPageType.AllowedTypes == null;

                if (allowedTypes != null && allowedTypes.Length == 0)
                {
                    PageTypeList.Text = "No pages can be created under the selected page.";
                    return;
                }
            }

            var stringBuilder = new StringBuilder();
            var count         = 0;

            foreach (var pageType in pageTypes.OrderBy(x => x.DisplayName))
            {
                if (!allowAll && !allowedTypes.Contains(pageType.Type))
                {
                    continue;
                }

                if (count > 0 && count % 2 == 0)
                {
                    stringBuilder.Append("</div><div class=\"row\">");
                }
                var previewImage = string.IsNullOrEmpty(pageType.PreviewImage) ? "assets/images/defaultpagetype.png" : pageType.PreviewImage;
                stringBuilder.Append("<div class=\"col-xs-6\"><a href=\"javascript:selectPageType('" + pageType.PageTypeId + "')\" class=\"no-decoration\"><div class=\"media pick-box\"><div class=\"pull-left\"><img class=\"media-object\" src=\"" + previewImage + "\"></div><div class=\"media-body\"><h2 class=\"media-heading\">" + pageType.DisplayName + "</h2>" + pageType.PageTypeDescription + "</div></div></a></div>");
                count++;
            }

            PageTypeList.Text = stringBuilder.ToString();
        }