Exemple #1
0
        /// <summary>
        /// Gets template from database manager result.
        /// </summary>
        /// <param name="dbm">Database manager.</param>
        /// <param name="loadAll">Set true to load template template pages, zones, configurable element types and elements. Otherwise only main template details loaded.</param>
        /// <returns>Template (or null if template not found).</returns>
        private Template GetTemplate(IDatabaseManager dbm, bool loadAll)
        {
            // Get template
            Template template = GetTemplateFromDatabaseManager(dbm);

            // If we are not reading entire template we can return result now
            if (!loadAll)
            {
                return(template);
            }

            // Get template pages and then construct template page hierarchy
            dbm.Read();
            Dictionary <long, TemplatePage> templatePagesById = new Dictionary <long, TemplatePage>();

            while (dbm.Read())
            {
                TemplatePage templatePage = GetTemplatePageFromDatabaseManager(dbm);
                templatePagesById.Add(templatePage.TemplatePageId, templatePage);
            }
            template.Page = GetTemplatePageHierarchy(templatePagesById);

            // Get template page zones
            Dictionary <long, TemplatePageZone> templatePageZonesById = new Dictionary <long, TemplatePageZone>();

            while (dbm.Read())
            {
                TemplatePageZone templatePageZone = GetTemplatePageZoneFromDatabaseManager(dbm);
                templatePagesById[templatePageZone.TemplatePageId].TemplatePageZones.Add(templatePageZone);
                templatePageZonesById.Add(templatePageZone.TemplatePageZoneId, templatePageZone);
            }

            // Get the element types that can exist in a template page zone when admin type is configurable
            while (dbm.Read())
            {
                TemplatePageZoneElementType templatePageZoneElementType = GetTemplatePageZoneElementTypeFromDatabaseManager(dbm);
                templatePageZonesById[templatePageZoneElementType.TemplatePageZoneId].TemplatePageZoneElementTypes.Add(templatePageZoneElementType);
            }

            // Get template page zone elements
            while (dbm.Read())
            {
                TemplatePageZoneElement templatePageZoneElement = GetTemplatePageZoneElementFromDatabaseManager(dbm);
                templatePageZonesById[templatePageZoneElement.TemplatePageZoneId].TemplatePageZoneElements.Add(templatePageZoneElement);
            }

            // Return the result
            return(template);
        }
Exemple #2
0
        /// <summary>
        /// Gets template page zone element from database manager data reader.
        /// </summary>
        /// <param name="dbm">Database manager.</param>
        /// <returns>A populated template page zone element object.</returns>
        private TemplatePageZoneElement GetTemplatePageZoneElementFromDatabaseManager(IDatabaseManager dbm)
        {
            TemplatePageZoneElement templatePageZoneElement = new TemplatePageZoneElement
            {
                TenantId                  = (long)dbm.DataReaderValue("TenantId"),
                TemplatePageId            = (long)dbm.DataReaderValue("TemplatePageId"),
                TemplatePageZoneId        = (long)dbm.DataReaderValue("TemplatePageZoneId"),
                TemplatePageZoneElementId = (long)dbm.DataReaderValue("TemplatePageZoneElementId"),
                SortOrder                 = (int)dbm.DataReaderValue("SortOrder"),
                ElementTypeId             = (Guid)dbm.DataReaderValue("ElementTypeId"),
                ElementId                 = (long)dbm.DataReaderValue("ElementId"),
                BeginRender               = dbm.DataReaderValue("BeginRender") == DBNull.Value ? null : (string)dbm.DataReaderValue("BeginRender"),
                EndRender                 = dbm.DataReaderValue("EndRender") == DBNull.Value ? null : (string)dbm.DataReaderValue("EndRender")
            };

            return(templatePageZoneElement);
        }