コード例 #1
0
        private SitemapModelNode CreateSiteMapNode(SitemapNode sitemapNode, int depth)
        {
            var node = new SitemapModelNode
            {
                Id            = sitemapNode.Page.ContentId,
                Name          = sitemapNode.Page.Name,
                PageId        = sitemapNode.Page.ContentId,
                VirtualPath   = sitemapNode.VirtualPath.ToString(),
                Depth         = depth,
                ParentPath    = sitemapNode?.VirtualPath.ToString(),
                HasChildItems = sitemapNode.ChildNodes.Any(),
                ChildNodes    = sitemapNode.ChildNodes.Select(x => CreateSiteMapNode(x, depth + 1)).ToList()
            };

            var uriBuilder = new CmsUriBuilder();

            Guid settingsPageId = Guid.Empty;
            var  draftNode      = sitemapNode;

            if (draftNode.Page.PageType == PageType.ContentPage)
            {
                try
                {
                    var uri = uriBuilder.CreateUri(draftNode.Page, UriSettings.Default, new Dictionary <string, string>
                    {
                        [PageDesignerUriComponents.ViewMode] = "PageDesigner",
                    });
                    node.DesignUrl = uri.ToString();
                }
                catch (Exception e)
                {
                    node.DesignUrl = $"/Admin/draft?{PageDesignerUriComponents.ViewMode}=PageDesigner&{PageDesignerUriComponents.SiteId}={draftNode.Page.SiteId}&{PageDesignerUriComponents.PageId}={node.PageId}";
                }

                settingsPageId = KnownPageIds.ContentPageSettings;
            }
            if (draftNode.Page.PageType == PageType.GroupingPage)
            {
                settingsPageId = KnownPageIds.GroupingPageSettings;
            }

            if (draftNode.Page.PageType == PageType.RedirectPage)
            {
                settingsPageId = KnownPageIds.RedirectPageSettings;
            }


            var success = CmsRoutes.Current.TryResolveRoute(settingsPageId, out var sr);

            if (success)
            {
                node.SettingsUrl = uriBuilder.CreateUriForRoute(sr, UriSettings.Default, new Dictionary <string, string> {
                    ["contentId"] = node.PageId.ToString()
                }).ToString();
            }



            return(node);
        }
コード例 #2
0
        protected void CreateNewItemButton_OnClick(object sender, EventArgs e)
        {
            Guid defaultSiteId       = Guid.Empty;
            var  defaultFrontendSite = SiteManagementContext.GetSiteToManage();

            if (defaultFrontendSite != null)
            {
                defaultSiteId = defaultFrontendSite.ContentId;
            }


            var uriBuilder = new CmsUriBuilder();
            var editPage   = new CmsPageRepository()
                             .FindContentVersions(By.ContentId(Config.AddPage), ContentEnvironment.Live)
                             .Result
                             .Single();

            var defaultValues = new DefaultValueCollection {
                ["SiteId"] = defaultSiteId.ToString()
            };
            var newPageUri = uriBuilder.CreateUri(editPage, UriSettings.Default, new Dictionary <string, string>
            {
                [nameof(DynamicFormRequestContext.DefaultValues)] = defaultValues.ToString()
            });

            Response.Redirect(newPageUri.PathAndQuery);
        }
コード例 #3
0
        public ViewResult Index()
        {
            var frontendSites = _siteRepository.GetFrontendSites();

            var rt       = WebPipeline.CurrentRequest;
            var siteId   = rt.Route.SiteId;
            var site     = _siteRepository.GetById(siteId);
            var livePage = new CmsPageRepository()
                           .FindContentVersions(By.ContentId(site.HomepageId.Value), ContentEnvironment.Live).Result;

            var uriBuilder = new CmsUriBuilder();
            var uri        = uriBuilder.CreateUri(
                livePage.Single(),
                UriSettings.Default,
                new Dictionary <string, string> {
                ["SiteId"] = siteId.ToString()
            });


            return(View(new NavigationBarViewModel
            {
                Sites = frontendSites.Select(x => new NavBarItem {
                    Text = x.Name, Url = uri.ToString()
                }).ToList(),
                TopLevelNavigationItems = CreateNavBarItems().ToList()
            }));
        }
コード例 #4
0
        private void PageTypeSelector_TextChanged(object sender, EventArgs e)
        {
            var parameters = Request.QueryString.ToDictionary();

            parameters[PageTypeParameter] = PageTypeSelector.SelectedValue;


            var newUrl = new CmsUriBuilder().CreateUri(WebPipeline.CurrentRequest.CmsPage, UriSettings.Default, parameters);

            Response.Redirect(newUrl.ToString());
        }
コード例 #5
0
        private NavBarItem CreateNavBarItem(SitemapNode node)
        {
            //var uriBuilderContext = System.Web.HttpContext.Current.ToUriBuilderContext();
            var uriBuilder = new CmsUriBuilder();
            var uri        = uriBuilder.CreateUri(node.Page, UriSettings.Default, null);

            var topLevel = new NavBarItem {
                Text = node.Page.Name, Url = uri.ToString(), ChildItems = new List <NavBarItem>()
            };

            foreach (var child in node.ChildNodes)
            {
                topLevel.ChildItems.Add(CreateNavBarItem(child));
            }

            return(topLevel);
        }
コード例 #6
0
        private string CreateUrl(SiteRoute transferRoute, IDictionary <string, string> parameters)
        {
            var uriBuilder = new CmsUriBuilder(httpRequest.ToUriBuilderContext());

            return(uriBuilder.CreateUriForRoute(transferRoute, UriSettings.Default, parameters).ToString());
        }