Ejemplo n.º 1
0
        public IActionResult ReadUpload(long elementId, long uploadId, string format)
        {
            // Get element service
            long                 tenantId        = _authenticationService.TenantId;
            IElementSettings     elementSettings = _elementService.Read(tenantId, elementId, false);
            IBasicElementService elementService  = _elementFactory.GetElementService(elementSettings.ElementTypeId);

            // If images not supported, go no further
            if (!(elementService is IUploadElementService))
            {
                return(null);
            }

            // Get specified image
            if (format == null)
            {
                format = "preview";
            }
            Upload upload = ((IUploadElementService)elementService).ReadUpload(tenantId, elementId, uploadId, format);

            if (upload == null)
            {
                return(null);
            }

            // Return file content result
            return(new FileContentResult(upload.Content, upload.ContentType)
            {
                FileDownloadName = upload.Name
            });
        }
Ejemplo n.º 2
0
        private IList <FormFieldSet> GetFieldSets(Dictionary <Guid, ElementType> elementTypesById, PageZone pageZone)
        {
            List <FormFieldSet> fieldSets = new List <FormFieldSet>();

            foreach (PageZoneElement pageZoneElement in pageZone.PageZoneElements)
            {
                FormFieldSet fieldSet = new FormFieldSet {
                    Fields = new Dictionary <string, IFormField>()
                };
                IElementSettings element = _elementService.Read(pageZoneElement.TenantId, pageZoneElement.ElementTypeId, pageZoneElement.ElementId);
                fieldSet.Fields.Add("name", GetNameTextField(pageZoneElement.PageZoneElementId, element.Name));
                fieldSet.Fields.Add("elementType", GetElementTypeSelectListField(pageZoneElement.PageZoneElementId, pageZoneElement.ElementTypeId, elementTypesById, null));
                fieldSets.Add(fieldSet);
            }
            return(fieldSets);
        }
Ejemplo n.º 3
0
        /// <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);
        }