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 void DetectDuplicateTemplateFileNames(PageBlockTypeFileDetails fileDetails) { // It's quite difficult to create duplicate template files since they should // all be in the same directory, but it is possible to spread between multiple // directories so we check to be sure. var duplicates = fileDetails .Templates .GroupBy(t => t.FileName) .Where(m => m.Count() > 1) .FirstOrDefault(); if (!EnumerableHelper.IsNullOrEmpty(duplicates)) { var duplicateNames = string.Join(", ", duplicates.Select(t => t.FileName)); throw new PageBlockTypeRegistrationException( $"Duplicate page block type templates '{ duplicates.Key }' detected. Conflicting template file names: { duplicateNames }"); } }