Пример #1
0
        /// <summary>
        /// Maps an EF PageBlockType record from the db into an PageBlockTypeDetails
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="blockTypeSummary">PageBlockType record from the database.</param>
        public PageBlockTypeDetails Map(PageBlockTypeSummary blockTypeSummary)
        {
            var result = new PageBlockTypeDetails()
            {
                Description     = blockTypeSummary.Description,
                FileName        = blockTypeSummary.FileName,
                Name            = blockTypeSummary.Name,
                PageBlockTypeId = blockTypeSummary.PageBlockTypeId,
                Templates       = blockTypeSummary.Templates
            };

            var dataModelType = GetPageBlockDataModelType(result);

            _dynamicDataModelTypeMapper.Map(result, dataModelType);

            return(result);
        }
        /// <summary>
        /// Maps an EF PageBlockType record from the db into an PageBlockTypeSummary
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbPageBlockType">PageBlockType record from the database.</param>
        public PageBlockTypeSummary Map(PageBlockType dbPageBlockType)
        {
            var result = new PageBlockTypeSummary()
            {
                Description     = dbPageBlockType.Description,
                FileName        = dbPageBlockType.FileName,
                Name            = dbPageBlockType.Name,
                PageBlockTypeId = dbPageBlockType.PageBlockTypeId
            };

            result.Templates = dbPageBlockType
                               .PageBlockTemplates
                               .Select(Map)
                               .ToList();

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Locates and returns the correct templates for a block if it a custom template
        /// assigned, otherwise null is returned.
        /// </summary>
        /// <param name="pageBlock">An unmapped database block to locate the template for.</param>
        /// <param name="blockType">The block type associated with the block in which to look for the template.</param>
        public PageBlockTypeTemplateSummary GetCustomTemplate(IEntityVersionPageBlock pageBlock, PageBlockTypeSummary blockType)
        {
            if (pageBlock == null)
            {
                throw new ArgumentNullException(nameof(pageBlock));
            }
            if (blockType == null)
            {
                throw new ArgumentNullException(nameof(blockType));
            }

            if (!pageBlock.PageBlockTypeTemplateId.HasValue)
            {
                return(null);
            }

            var template = blockType
                           .Templates
                           .FirstOrDefault(t => t.PageBlockTypeTemplateId == pageBlock.PageBlockTypeTemplateId);

            if (template == null)
            {
                _logger.LogDebug("The block template with id {PageBlockTypeTemplateId} could not be found for {PageBlockType} {VersionBlockId}", pageBlock.PageBlockTypeTemplateId, pageBlock.GetType().Name, pageBlock.GetVersionBlockId());
            }

            return(template);
        }