Ejemplo n.º 1
0
        /// <summary>
        /// Get elements for master pages belonging to the specified tenant.
        /// </summary>
        /// <param name="tenantId">Tenant identifier.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Collection of elements.</returns>
        public IEnumerable <MasterPage> ListElementsByMasterPage(long tenantId, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                List <MasterPage> masterPages = new List <MasterPage>();
                dbm.SetSQL(_sqlManager.GetSql("Sql.ListMasterPageElements.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId);
                dbm.ExecuteReader();
                MasterPage            masterPage            = null;
                MasterPageZone        masterPageZone        = null;
                MasterPageZoneElement masterPageZoneElement = null;
                while (dbm.Read())
                {
                    // Get master page details, create new master page each time master page identifier changes
                    long masterPageId = (long)dbm.DataReaderValue("MasterPageId");
                    if (masterPage == null || masterPage.MasterPageId != masterPageId)
                    {
                        masterPage = new MasterPage {
                            TenantId = tenantId, MasterPageId = masterPageId, Name = (string)dbm.DataReaderValue("MasterPageName"), MasterPageZones = new List <MasterPageZone>()
                        };
                        masterPages.Add(masterPage);
                        masterPageZone        = null;
                        masterPageZoneElement = null;
                    }

                    // Get master page zone details, create new master page zone each time master page zone identifier changes
                    long masterPageZoneId = (long)dbm.DataReaderValue("MasterPageZoneId");
                    if (masterPageZone == null || masterPageZone.MasterPageZoneId != masterPageZoneId)
                    {
                        masterPageZone = new MasterPageZone {
                            TenantId = tenantId, MasterPageId = masterPageId, MasterPageZoneId = masterPageZoneId, Name = (string)dbm.DataReaderValue("MasterPageZoneName"), MasterPageZoneElements = new List <MasterPageZoneElement>()
                        };
                        masterPage.MasterPageZones.Add(masterPageZone);
                        masterPageZoneElement = null;
                    }

                    // Get master page zone element details, create new master page zone element each time master page zone element identifier changes
                    long masterPageZoneElementId = (long)dbm.DataReaderValue("MasterPageZoneElementId");
                    if (masterPageZoneElement == null || masterPageZoneElement.MasterPageZoneElementId != masterPageZoneElementId)
                    {
                        masterPageZoneElement = new MasterPageZoneElement {
                            TenantId = tenantId, MasterPageId = masterPageId, MasterPageZoneId = masterPageZoneId, MasterPageZoneElementId = masterPageZoneElementId
                        };
                        masterPageZone.MasterPageZoneElements.Add(masterPageZoneElement);
                    }

                    // Get element details
                    masterPageZoneElement.Element = new ElementSettings {
                        TenantId = tenantId, ElementId = (long)dbm.DataReaderValue("ElementId"), ElementTypeId = (Guid)dbm.DataReaderValue("ElementTypeId"), Name = (string)dbm.DataReaderValue("Name")
                    };
                    masterPageZoneElement.ElementId = masterPageZoneElement.Element.ElementId;
                }
                return(masterPages);
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves form for master page zone update.
        /// </summary>
        /// <param name="context">Form context.</param>
        /// <returns>Form object.</returns>
        private Form GetMasterPageZoneForm(string context)
        {
            // Get tenant identifier
            long tenantId = _authenticationService.TenantId;

            // Get identifier of master page zone that is being updated
            string[] parts = context.Split('|');
            long masterPageId = Convert.ToInt64(parts[0]);
            long masterPageZoneId = Convert.ToInt64(parts[1]);

            // Get existing master page details
            MasterPage masterPage = _masterPageService.Read(tenantId, masterPageId);
            MasterPageZone masterPageZone = masterPage.MasterPageZones.Where(mpz => mpz.MasterPageZoneId == masterPageZoneId).FirstOrDefault();

            // Construct form
            Form form = new Form { Fields = new Dictionary<string, IFormField>(), Id = FormId.ToString(), Context = context, SubmitLabel = MasterPageResource.UpdateZoneButtonLabel };
            form.Fields.Add("name", new TextField
            {
                Name = "zoneName",
                Label = MasterPageResource.ZoneNameLabel,
                Required = true,
                RequiredErrorMessage = MasterPageResource.ZoneNameRequiredMessage,
                MaxLength = MasterPageLengths.ZoneNameMaxLength,
                MaxLengthErrorMessage = string.Format(MasterPageResource.ZoneNameMaxLengthMessage, "name", MasterPageLengths.ZoneNameMaxLength)
            });
            form.Fields.Add("adminType", new SelectListField<string>
            {
                Name = "adminType",
                Label = MasterPageResource.AdminTypeLabel,
                Items = new List<ListFieldItem<string>> {
                    new ListFieldItem<string> { Name = _dataAnnotationsService.GetEnumDisplayName<MasterPageZoneAdminType>(MasterPageZoneAdminType.Static), Value = ((int)MasterPageZoneAdminType.Static).ToString() },
                    new ListFieldItem<string> { Name = _dataAnnotationsService.GetEnumDisplayName<MasterPageZoneAdminType>(MasterPageZoneAdminType.Editable), Value = ((int)MasterPageZoneAdminType.Editable).ToString() },
                    new ListFieldItem<string> { Name = _dataAnnotationsService.GetEnumDisplayName<MasterPageZoneAdminType>(MasterPageZoneAdminType.Configurable), Value = ((int)MasterPageZoneAdminType.Configurable).ToString() }
                },
                Required = true,
                RequiredErrorMessage = MasterPageResource.AdminTypeRequiredMessage
            });
            form.Fields.Add("contentType", new SelectListField<string>
            {
                Name = "contentType",
                Label = MasterPageResource.ContentTypeLabel,
                Items = new List<ListFieldItem<string>> {
                    new ListFieldItem<string> { Name = _dataAnnotationsService.GetEnumDisplayName<MasterPageZoneContentType>(MasterPageZoneContentType.Standard), Value = ((int)MasterPageZoneContentType.Standard).ToString() },
                    new ListFieldItem<string> { Name = _dataAnnotationsService.GetEnumDisplayName<MasterPageZoneContentType>(MasterPageZoneContentType.Main), Value = ((int)MasterPageZoneContentType.Main).ToString() },
                    new ListFieldItem<string> { Name = _dataAnnotationsService.GetEnumDisplayName<MasterPageZoneContentType>(MasterPageZoneContentType.Comment), Value = ((int)MasterPageZoneContentType.Comment).ToString() }
                },
                Required = true,
                RequiredErrorMessage = MasterPageResource.ContentTypeRequiredMessage
            });
            form.Fields.Add("beginRender", new MultiLineTextField
            {
                Name = "beginRenderZone",
                Label = MasterPageResource.ZoneBeginRenderLabel,
                Rows = 4
            });
            form.Fields.Add("endRender", new MultiLineTextField
            {
                Name = "endRenderZone",
                Label = MasterPageResource.ZoneEndRenderLabel,
                Rows = 4,
                Value = masterPageZone.EndRender
            });

            // Create sub forms
            form.SubForms = new Dictionary<string, Form>();
            form.SubForms.Add("zoneElement", GetMasterPageZoneElementForm(context));
            form.SubForms.Add("zoneElementNew", GetMasterPageZoneElementNewForm(context));
            form.SubForms.Add("zoneElementType", GetMasterPageZoneElementTypeForm(context));

            // Set master page zone as form data
            form.Data = JsonConvert.SerializeObject(masterPageZone);

            // Return form
            return form;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new master page.
 /// </summary>
 /// <param name="masterPage">Contains details of new master page to create.</param>
 /// <param name="unitOfWork">Unit of work.</param>
 /// <returns>Newly allocated master page identifier.</returns>
 public long Create(MasterPage masterPage, IUnitOfWork unitOfWork = null)
 {
     return(_masterPageRepository.Create(masterPage, unitOfWork));
 }