Example #1
0
        /// <summary>
        /// Reads primary element details.
        /// </summary>
        /// <param name="tenantId">Tenant that element associated with.</param>
        /// <param name="elementId">Element identifier.</param>
        /// <param name="loadCustomSettings">Set false to retrieve only those settings common to all elements. Set true to retrieve settings common to all elements and element specific settings.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Element setings (null if element not found).</returns>
        public IElementSettings Read(long tenantId, long elementId, bool loadCustomSettings, IUnitOfWork unitOfWork = null)
        {
            // Get core element details
            IElementSettings elementSettings = _elementRepository.Read(tenantId, elementId, unitOfWork);

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

            // Now we know the type of element requested, we can get custom element settings
            IBasicElementService customElementService  = _elementFactory.GetElementService(elementSettings.ElementTypeId);
            IElementSettings     customElementSettings = customElementService.New(elementSettings.TenantId);

            customElementSettings.ElementId = elementSettings.ElementId;
            customElementSettings.Name      = elementSettings.Name;

            // If "advanced" element, populate custom settings
            if (loadCustomSettings && customElementService is IAdvancedElementService)
            {
                ((IAdvancedElementService)customElementService).Read(customElementSettings, unitOfWork);
            }

            // Return fully populated element settings
            return(customElementSettings);
        }
Example #2
0
        /// <summary>
        /// Gets element details.
        /// </summary>
        /// <param name="tenantId">Identifies the tenant that element belongs to.</param>
        /// <param name="elementTypeId">The type of the element.</param>
        /// <param name="elementId">Identifies the element to return.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Element settings (or null if element not found).</returns>
        public IElementSettings Read(long tenantId, Guid elementTypeId, long elementId, IUnitOfWork unitOfWork = null)
        {
            // Construct instance of element settings
            IBasicElementService customElementService = _elementFactory.GetElementService(elementTypeId);
            IElementSettings     settings             = customElementService.New(tenantId);

            // Populate element ID
            settings.ElementId = elementId;

            // Populate for advanced elements
            if (customElementService is IAdvancedElementService)
            {
                // Populate element with common settings
                _elementRepository.Read(settings, unitOfWork);

                // Populate with custom settings
                ((IAdvancedElementService)customElementService).Read(settings, unitOfWork);
            }

            // Return fully populated element
            return(settings);
        }