public async Task <IActionResult> ReadMasterPageZoneElementAsync(long masterPageId, long masterPageZoneId, long masterPageZoneElementId) { MasterPageZoneElement masterPageZoneElement = await _masterPageService.ReadMasterPageZoneElementAsync(TenantId, masterPageId, masterPageZoneId, masterPageZoneElementId); if (masterPageZoneElement == null) { return(NotFound()); } return(Ok(masterPageZoneElement)); }
public async Task <MasterPageZoneElement> ReadMasterPageZoneElementAsync(long tenantId, long masterPageId, long masterPageZoneId, long masterPageZoneElementId) { using (SqlConnection connection = new SqlConnection(_options.Value.SqlConnectionString)) { connection.Open(); MasterPageZoneElement masterPageZoneElement = await connection.QueryFirstOrDefaultAsync <MasterPageZoneElement>( @"SELECT cms.MasterPageZoneElement.TenantId, cms.MasterPageZoneElement.MasterPageId, cms.MasterPageZoneElement.MasterPageZoneId, cms.MasterPageZoneElement.MasterPageZoneElementId, cms.MasterPageZoneElement.SortOrder, cms.Element.ElementTypeId, cms.MasterPageZoneElement.ElementId, cms.MasterPageZoneElement.BeginRender, cms.MasterPageZoneElement.EndRender FROM cms.MasterPageZoneElement INNER JOIN cms.Element ON cms.MasterPageZoneElement.TenantId = cms.Element.TenantId AND cms.MasterPageZoneElement.ElementId = cms.Element.ElementId WHERE cms.MasterPageZoneElement.TenantId = @TenantId AND cms.MasterPageZoneElement.MasterPageId = @MasterPageId AND cms.MasterPageZoneElement.MasterPageZoneId = @MasterPageZoneId AND cms.MasterPageZoneElement.MasterPageZoneElementId = @MasterPageZoneElementId", new { TenantId = tenantId, MasterPageId = masterPageId, MasterPageZoneId = masterPageZoneId, MasterPageZoneElementId = masterPageZoneElementId } ); return(masterPageZoneElement); } }
/// <summary> /// Retrieves page for display. /// </summary> /// <param name="tenantId">Website whose page is read.</param> /// <param name="pageContext">Page context.</param> /// <returns>View model required to render a page.</returns> public PageViewModel GetPageViewModelFromPageContext(IPageContext pageContext) { // Construct page view model PageViewModel pageViewModel = new PageViewModel { Administration = pageContext.MasterPage.Administration, PageContext = pageContext, BeginRender = FormatLayoutHtml(pageContext.Page, pageContext.MasterPage.BeginRender), EndRender = FormatLayoutHtml(pageContext.Page, pageContext.MasterPage.EndRender), PageZoneViewModels = new List <PageZoneViewModel>(), Title = GetPageTitle(pageContext), MetaKeywords = GetMetaKeywords(pageContext.Page), MetaDescription = GetMetaDescription(pageContext.Page), AssetStyleSheetPath = _assetService.GetAssetStyleSheetPath(pageContext.Web.TenantId), FontOptionStyleSheetPath = _assetService.GetFontOptionStyleSheetPath(pageContext.Web.TenantId, pageContext.Web.FontOption), ColourOptionStyleSheetPath = _assetService.GetColourOptionStyleSheetPath(pageContext.Web.TenantId, pageContext.Web.ColourOption), ForumAction = GetForumAction(), AssetElementTypes = _assetService.GetAssetElementTypes(pageContext.Web.TenantId), StockElementViewPath = "~/Views/Elements", AssetElementViewPath = _assetService.GetElementViewPath(pageContext.Web.TenantId) }; // Maintain lists of page elements, master elements and configurable page zones List <IElementInfo> pageElements = new List <IElementInfo>(); List <IElementInfo> masterElements = new List <IElementInfo>(); List <PageZone> configurablePageZones = new List <PageZone>(); // Get page zones by master page zone ID Dictionary <long, PageZone> pageZonesByMasterPageZoneId = new Dictionary <long, PageZone>(); foreach (PageZone pageZone in pageContext.Page.PageZones) { pageZonesByMasterPageZoneId.Add(pageZone.MasterPageZoneId, pageZone); } // Populate page zone view models foreach (MasterPageZone masterPageZone in pageContext.MasterPage.MasterPageZones) { // Construct page zone view model PageZoneViewModel pageZoneViewModel = new PageZoneViewModel { BeginRender = FormatLayoutHtml(pageContext.Page, masterPageZone.BeginRender), EndRender = FormatLayoutHtml(pageContext.Page, masterPageZone.EndRender), ContentType = masterPageZone.ContentType, PageZoneElementViewModels = new List <PageZoneElementViewModel>() }; // Get page zone element view models PageZone pageZone; if (pageZonesByMasterPageZoneId.TryGetValue(masterPageZone.MasterPageZoneId, out pageZone)) { // Associate master page zone with page zone pageZone.MasterPageZone = masterPageZone; // If master page zone admin type is Editable, sort order is NULL at PageZoneElement level and we must use sort order stored in MasterPageZoneElement Dictionary <long, MasterPageZoneElement> masterPageZoneElementsById = null; if (masterPageZone.AdminType == MasterPageZoneAdminType.Editable) { // If admin type is Editable, then defer to MasterPageZoneElement level for ordering masterPageZoneElementsById = new Dictionary <long, MasterPageZoneElement>(); foreach (MasterPageZoneElement masterPageZoneElement in masterPageZone.MasterPageZoneElements) { masterPageZoneElementsById.Add(masterPageZoneElement.MasterPageZoneElementId, masterPageZoneElement); } foreach (PageZoneElement pageZoneElement in pageZone.PageZoneElements) { MasterPageZoneElement masterPageZoneElement = masterPageZoneElementsById[pageZoneElement.MasterPageZoneElementId.Value]; pageZoneElement.SortOrder = masterPageZoneElement.SortOrder; } pageZone.PageZoneElements.Sort(new PageZoneElementComparer()); } // Get page zone element view models from page if (masterPageZone.AdminType == MasterPageZoneAdminType.Configurable) { configurablePageZones.Add(pageZone); } foreach (PageZoneElement pageZoneElement in pageZone.PageZoneElements) { IElementSettings settings = _elementService.Read(pageContext.Web.TenantId, pageZoneElement.ElementTypeId, pageZoneElement.ElementId); IElementContent content = _elementService.GetContent(settings, pageContext); IElementInfo info = _elementService.NewInfo(settings, content); pageElements.Add(info); PageZoneElementViewModel pageZoneElementViewModel = new PageZoneElementViewModel { ElementInfo = info }; if (masterPageZone.AdminType == MasterPageZoneAdminType.Editable) { pageZoneElementViewModel.BeginRender = masterPageZoneElementsById[pageZoneElement.MasterPageZoneElementId.Value].BeginRender; pageZoneElementViewModel.EndRender = masterPageZoneElementsById[pageZoneElement.MasterPageZoneElementId.Value].EndRender; } pageZoneViewModel.PageZoneElementViewModels.Add(pageZoneElementViewModel); } } else { // Get page zone element view models from master page foreach (MasterPageZoneElement masterPageZoneElement in masterPageZone.MasterPageZoneElements) { IElementSettings settings = _elementService.Read(pageContext.Web.TenantId, masterPageZoneElement.Element.ElementTypeId, masterPageZoneElement.ElementId); IElementContent content = _elementService.GetContent(settings, pageContext); IElementInfo info = _elementService.NewInfo(settings, content); masterElements.Add(info); pageZoneViewModel.PageZoneElementViewModels.Add(new PageZoneElementViewModel { ElementInfo = info, BeginRender = masterPageZoneElement.BeginRender, EndRender = masterPageZoneElement.EndRender }); } } // Register page zone view model pageViewModel.PageZoneViewModels.Add(pageZoneViewModel); } // Pass administration options to elements that can display them IAdministrationOptions options = _administrationService.GetAdministrationOptions(pageContext, pageElements, masterElements, configurablePageZones); List <IElementInfo> administrationElements = GetElementsWithContent <IAdministrationContent>(pageViewModel); foreach (IElementInfo elementInfo in administrationElements) { ((IAdministrationContent)elementInfo.Content).Options = options; } SetConsumerPageLinks(pageViewModel); pageViewModel.Options = options; // Return the resulting page view model return(pageViewModel); }