예제 #1
0
        private void UpdateTemplates(
            IExecutionContext executionContext,
            PageBlockType existingBlock,
            PageBlockTypeFileDetails fileDetails
            )
        {
            var templatesToDelete = existingBlock
                                    .PageBlockTemplates
                                    .Where(mt => !fileDetails.Templates.Any(t => t.FileName.Equals(mt.FileName, StringComparison.OrdinalIgnoreCase)))
                                    .ToList();

            if (templatesToDelete.Any())
            {
                _dbContext.PageBlockTypeTemplates.RemoveRange(templatesToDelete);
            }

            foreach (var fileTemplate in fileDetails.Templates)
            {
                var existingTemplate = existingBlock
                                       .PageBlockTemplates
                                       .FirstOrDefault(t => t.FileName.Equals(fileTemplate.FileName, StringComparison.OrdinalIgnoreCase));

                if (existingTemplate == null)
                {
                    existingTemplate            = new PageBlockTypeTemplate();
                    existingTemplate.CreateDate = executionContext.ExecutionDate;
                    existingBlock.PageBlockTemplates.Add(existingTemplate);
                }

                existingTemplate.FileName    = fileTemplate.FileName;
                existingTemplate.Name        = fileTemplate.Name;
                existingTemplate.Description = fileTemplate.Description;
            }
        }
        private PageBlockTypeTemplateSummary Map(PageBlockTypeTemplate dbTemplate)
        {
            var result = new PageBlockTypeTemplateSummary()
            {
                FileName = dbTemplate.FileName,
                Name     = dbTemplate.Name,
                PageBlockTypeTemplateId = dbTemplate.PageBlockTypeTemplateId
            };

            return(result);
        }
        /// <summary>
        /// Some properties of the template are generated based on the file name and these
        /// should be validated to ensure that they do not exceed the database column sizes.
        /// </summary>
        private static void ValidateTemplateProperties(PageBlockTypeTemplate dbPageBlockTypeTemplate)
        {
            if (string.IsNullOrWhiteSpace(dbPageBlockTypeTemplate.Name))
            {
                throw new PageBlockTypeRegistrationException($"Page block type template name cannot be null. FileName: {dbPageBlockTypeTemplate.FileName}");
            }

            if (dbPageBlockTypeTemplate.Name.Length > 50)
            {
                throw new PageBlockTypeRegistrationException($"Page block type template name exceeds the maximum length of 50 characters: {dbPageBlockTypeTemplate.Name}");
            }

            if (dbPageBlockTypeTemplate.FileName.Length > 50)
            {
                throw new PageBlockTypeRegistrationException($"Page block type template file name exceeds the maximum length of 50 characters: {dbPageBlockTypeTemplate.FileName}");
            }
        }