diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index a1716767a..63c251451 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; + using LearningHub.Nhs.Models.Entities.Resource; using LearningHub.Nhs.Models.Enums; using LearningHub.Nhs.Models.Resource; using LearningHub.Nhs.Models.Resource.Blocks; @@ -493,7 +494,11 @@ public async Task SaveCaseDetailAsync([FromBody] CaseViewModel req { var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); int resourceVersionId = await this.contributeService.SaveCaseDetailAsync(request); - this.RemoveDeletedCaseFiles(existingResourceState?.CaseDetails, request); + if (existingResourceState.CaseDetails?.BlockCollection != null) + { + this.RemoveBlockCollectionFiles(existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); + } + return this.Ok(resourceVersionId); } @@ -506,7 +511,13 @@ public async Task SaveCaseDetailAsync([FromBody] CaseViewModel req [Route("SaveAssessmentDetail")] public async Task SaveAssessmentDetailAsync([FromBody] AssessmentViewModel request) { + var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); int resourceVersionId = await this.contributeService.SaveAssessmentDetailAsync(request); + if (existingResourceState != null && existingResourceState.AssessmentDetails != null) + { + this.RemoveBlockCollectionFiles(existingResourceState.AssessmentDetails, request); + } + return this.Ok(resourceVersionId); } @@ -627,15 +638,28 @@ private async Task UserCanEditCatalogue(int catalogueId) return await this.catalogueService.CanCurrentUserEditCatalogue(catalogueId); } - private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewModel newResource) + private void RemoveBlockCollectionFiles(AssessmentViewModel existingModel, AssessmentViewModel newModel) + { + if (existingModel is { EndGuidance: { } } && existingModel.EndGuidance.Blocks != null) + { + this.RemoveBlockCollectionFiles(existingModel.EndGuidance, newModel.EndGuidance); + } + + if (existingModel is { AssessmentContent: { } } && existingModel.AssessmentContent.Blocks != null) + { + this.RemoveBlockCollectionFiles(existingModel.AssessmentContent, newModel.AssessmentContent); + } + } + + private void RemoveBlockCollectionFiles(BlockCollectionViewModel existingResource, BlockCollectionViewModel newResource) { try { var filePaths = new List(); - if (existingResource != null && existingResource.BlockCollection != null) + if (existingResource != null) { - var allBlocks = existingResource.BlockCollection.Blocks.ToList(); - var newBlocks = newResource.BlockCollection.Blocks.ToList(); + var allBlocks = existingResource.Blocks.ToList(); + var newBlocks = newResource.Blocks.ToList(); if (allBlocks.Any()) { var existingAttachements = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null).ToList(); @@ -659,10 +683,19 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Video && x.MediaBlock.Video != null && x.MediaBlock.Video.VideoFile?.File?.FileId == oldblock.MediaBlock?.Video?.VideoFile?.File?.FileId); if (entry == null) { - filePaths.Add(oldblock.MediaBlock.Video?.VideoFile?.File?.FilePath); - if (oldblock.MediaBlock?.Video?.VideoFile?.TranscriptFile?.File?.FilePath != null) + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video.File.FilePath)) + { + filePaths.Add(oldblock.MediaBlock.Video.File.FilePath); + } + + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video?.File?.VideoFile?.File?.FilePath)) { - filePaths.Add(oldblock.MediaBlock.Video?.VideoFile?.TranscriptFile?.File?.FilePath); + filePaths.Add(oldblock.MediaBlock.Video.File.VideoFile.File.FilePath); + } + + if (oldblock.MediaBlock?.Video?.File?.VideoFile?.TranscriptFile?.File?.FilePath != null) + { + filePaths.Add(oldblock.MediaBlock.Video.File.VideoFile.TranscriptFile.File.FilePath); } } } @@ -713,6 +746,27 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode } } } + + var existingQuestionFiles = this.CheckQuestionBlock(existingResource); + var newQuestionFiles = this.CheckQuestionBlock(newResource); + if (existingQuestionFiles.Any()) + { + if (!newQuestionFiles.Any()) + { + filePaths.AddRange(existingQuestionFiles); + } + else + { + foreach (var file in existingQuestionFiles) + { + var entry = newQuestionFiles.FirstOrDefault(x => x.Equals(file)); + if (entry == null) + { + filePaths.Add(file); + } + } + } + } } if (filePaths != null && filePaths.Any()) @@ -724,5 +778,117 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode { } } + + private List CheckQuestionBlock(BlockCollectionViewModel model) + { + var filePath = new List(); + foreach (var block in model.Blocks) + { + if (block.BlockType == BlockType.Question && block.QuestionBlock != null) + { + if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) + { + foreach (var answerBlock in block.QuestionBlock.Answers) + { + if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null) + { + foreach (var imageBlock in answerBlock.BlockCollection.Blocks) + { + if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + { + filePath.Add(imageBlock.MediaBlock.Image.File.FilePath); + } + } + } + } + } + + var questionBlockCollection = block.QuestionBlock.QuestionBlockCollection; + if (questionBlockCollection != null && questionBlockCollection.Blocks != null) + { + foreach (var questionBlock in questionBlockCollection.Blocks) + { + if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) + { + if (questionBlock.MediaBlock.Image != null) + { + filePath.Add(questionBlock.MediaBlock.Image.File.FilePath); + } + + if (questionBlock.MediaBlock.Video != null) + { + if (questionBlock.MediaBlock.Video.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); + } + + if (questionBlock.MediaBlock.Video.VideoFile != null) + { + if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) + { + filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); + } + + if (questionBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + { + filePath.Add(questionBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + } + } + } + } + else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null) + { + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.ToList(); + if (existingWholeSlideImages.Any()) + { + foreach (var wsi in existingWholeSlideImages) + { + filePath.Add(wsi.WholeSlideImage?.File?.FilePath); + } + } + } + } + } + + var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; + if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null) + { + foreach (var feedbackBlock in feedbackBlockCollection.Blocks) + { + if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) + { + if (feedbackBlock.MediaBlock.Image != null) + { + filePath.Add(feedbackBlock.MediaBlock.Image.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video != null) + { + if (feedbackBlock.MediaBlock.Video.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video.VideoFile != null) + { + if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + } + } + } + } + } + } + } + } + + return filePath; + } } } diff --git a/LearningHub.Nhs.WebUI/Services/FileService.cs b/LearningHub.Nhs.WebUI/Services/FileService.cs index af8d5572c..0e6fce092 100644 --- a/LearningHub.Nhs.WebUI/Services/FileService.cs +++ b/LearningHub.Nhs.WebUI/Services/FileService.cs @@ -230,50 +230,10 @@ public async Task PurgeResourceFile(ResourceVersionExtendedViewModel vm = null, { allContentPath.Add(vm.ScormDetails.ContentFilePath); } - else if (vm.GenericFileDetails != null && !string.IsNullOrWhiteSpace(vm.GenericFileDetails.File.FilePath)) - { - allFilePath.Add(vm.GenericFileDetails.File.FilePath); - } else if (vm.HtmlDetails != null && !string.IsNullOrWhiteSpace(vm.HtmlDetails.ContentFilePath)) { allContentPath.Add(vm.HtmlDetails.ContentFilePath); } - else if (vm.ImageDetails != null && !string.IsNullOrWhiteSpace(vm.ImageDetails.File?.FilePath)) - { - allFilePath.Add(vm.ImageDetails.File?.FilePath); - } - else if (vm.ArticleDetails != null) - { - var files = vm.ArticleDetails.Files.ToList(); - if (files.Any()) - { - foreach (var file in files) - { - allFilePath.Add(file.FilePath); - } - } - } - else if (vm.CaseDetails != null) - { - var blockCollection = vm.CaseDetails.BlockCollection; - foreach (var entry in blockCollection.Blocks) - { - if (entry.ImageCarouselBlock != null) - { - foreach (var item in entry.ImageCarouselBlock?.ImageBlockCollection?.Blocks) - { - allFilePath.Add(item?.MediaBlock?.Image?.File.FilePath); - } - } - else if (entry.WholeSlideImageBlock != null) - { - foreach (var item in entry.WholeSlideImageBlock.WholeSlideImageBlockItems) - { - allFilePath.Add(item?.WholeSlideImage?.File.FilePath); - } - } - } - } // audio and video to be added await this.MoveInPutDirectoryToArchive(allFilePath); diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index 9453b4208..7c7974798 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -1471,73 +1471,40 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b } } } - else if (resource.ResourceTypeEnum == ResourceTypeEnum.Case) + else if (resource.ResourceTypeEnum == ResourceTypeEnum.Assessment) { if (deletedResource) { - if (resource != null) + if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) { - var allBlocks = resource.CaseDetails.BlockCollection.Blocks.ToList(); - if (allBlocks.Any()) + var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.EndGuidance); + if (assessmentFiles.Any()) { - var existingAttachements = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null).ToList(); - if (existingAttachements.Any()) - { - foreach (var oldblock in existingAttachements) - { - retVal.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); - } - } - - var existingVideos = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Video && x.MediaBlock.Video != null).ToList(); - if (existingVideos.Any()) - { - foreach (var oldblock in existingVideos) - { - retVal.Add(oldblock.MediaBlock.Video?.VideoFile?.File?.FilePath); - if (oldblock.MediaBlock?.Video?.VideoFile.TranscriptFile?.File.FilePath != null) - { - retVal.Add(oldblock.MediaBlock.Video?.VideoFile?.TranscriptFile?.File?.FilePath); - } - } - } - - var existingImages = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null).ToList(); - if (existingImages.Any()) - { - foreach (var oldblock in existingImages) - { - retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); - } - } - - var existingImageCarousel = allBlocks.Where(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null).ToList(); - if (existingImageCarousel.Any()) - { - foreach (var imageBlock in existingImageCarousel) - { - foreach (var oldblock in imageBlock.ImageCarouselBlock.ImageBlockCollection.Blocks) - { - retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); - } - } - } + retVal.AddRange(assessmentFiles); + } + } - var existingWholeSlideImages = allBlocks.Where(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Any()).ToList(); - if (existingWholeSlideImages.Any()) - { - foreach (var wsi in existingWholeSlideImages) - { - foreach (var oldblock in wsi.WholeSlideImageBlock.WholeSlideImageBlockItems) - { - retVal.Add(oldblock.WholeSlideImage?.File?.FilePath); - } - } - } + if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) + { + var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.AssessmentContent); + if (assessmentFiles.Any()) + { + retVal.AddRange(assessmentFiles); } } } } + else if (resource.ResourceTypeEnum == ResourceTypeEnum.Case) + { + if (deletedResource) + { + var caseFiles = this.CheckBlockFile(resource.CaseDetails.BlockCollection); + if (caseFiles.Any()) + { + retVal.AddRange(caseFiles); + } + } + } } else if (rv == null && deletedResource) { @@ -1559,7 +1526,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b } else if (resource.ResourceTypeEnum == ResourceTypeEnum.Audio) { - retVal.Add(resource.AudioDetails.File.FilePath); + retVal.Add(resource.AudioDetails?.File?.FilePath); if (resource.AudioDetails?.ResourceAzureMediaAsset?.FilePath != null) { retVal.Add(resource.AudioDetails.ResourceAzureMediaAsset.FilePath); @@ -1567,7 +1534,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b } else if (resource.ResourceTypeEnum == ResourceTypeEnum.Video) { - retVal.Add(resource.VideoDetails.File.FilePath); + retVal.Add(resource.VideoDetails?.File?.FilePath); if (resource.VideoDetails?.ResourceAzureMediaAsset?.FilePath != null) { retVal.Add(resource.VideoDetails.ResourceAzureMediaAsset.FilePath); @@ -1584,67 +1551,37 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b } } } - else if (resource.ResourceTypeEnum == ResourceTypeEnum.Case) + else if (resource.ResourceTypeEnum == ResourceTypeEnum.Assessment) { - var allBlocks = resource.CaseDetails.BlockCollection.Blocks.ToList(); - if (allBlocks.Any()) + if (deletedResource) { - var existingAttachements = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null).ToList(); - if (existingAttachements.Any()) + if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) { - foreach (var oldblock in existingAttachements) + var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.EndGuidance); + if (assessmentFiles.Any()) { - retVal.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); + retVal.AddRange(assessmentFiles); } } - var existingVideos = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Video && x.MediaBlock.Video != null).ToList(); - if (existingVideos.Any()) + if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) { - foreach (var oldblock in existingVideos) + var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.AssessmentContent); + if (assessmentFiles.Any()) { - retVal.Add(oldblock.MediaBlock.Video?.VideoFile?.File?.FilePath); - if (oldblock.MediaBlock?.Video?.VideoFile.TranscriptFile?.File.FilePath != null) - { - retVal.Add(oldblock.MediaBlock.Video?.VideoFile?.TranscriptFile?.File?.FilePath); - } - } - } - - var existingImages = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null).ToList(); - if (existingImages.Any()) - { - foreach (var oldblock in existingImages) - { - retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); - } - } - - var existingImageCarousel = allBlocks.Where(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null).ToList(); - if (existingImageCarousel.Any()) - { - foreach (var imageBlock in existingImageCarousel) - { - foreach (var oldblock in imageBlock?.ImageCarouselBlock?.ImageBlockCollection.Blocks) - { - retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); - } - } - } - - var existingWholeSlideImages = allBlocks.Where(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Any()).ToList(); - if (existingWholeSlideImages.Any()) - { - foreach (var wsi in existingWholeSlideImages) - { - foreach (var oldblock in wsi.WholeSlideImageBlock?.WholeSlideImageBlockItems) - { - retVal.Add(oldblock.WholeSlideImage?.File?.FilePath); - } + retVal.AddRange(assessmentFiles); } } } } + else if (resource.ResourceTypeEnum == ResourceTypeEnum.Case) + { + var caseFiles = this.CheckBlockFile(resource.CaseDetails.BlockCollection); + if (caseFiles.Any()) + { + retVal.AddRange(caseFiles); + } + } } return retVal; @@ -4946,5 +4883,201 @@ private async Task CreateNewResource(ResourceTypeEnum resourceType, string return resourceVersionId; } + + private List CheckBlockFile(BlockCollectionViewModel model) + { + var retVal = new List(); + var caseBlockCollection = model; + if (caseBlockCollection != null) + { + var allBlocks = caseBlockCollection.Blocks.ToList(); + if (allBlocks.Any()) + { + var existingAttachements = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null).ToList(); + if (existingAttachements.Any()) + { + foreach (var oldblock in existingAttachements) + { + retVal.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); + } + } + + var existingVideos = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Video && x.MediaBlock.Video != null).ToList(); + if (existingVideos.Any()) + { + foreach (var oldblock in existingVideos) + { + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video.File.FilePath)) + { + retVal.Add(oldblock.MediaBlock.Video.File.FilePath); + } + + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video?.File?.VideoFile?.File?.FilePath)) + { + retVal.Add(oldblock.MediaBlock.Video.File.VideoFile.File.FilePath); + } + + if (oldblock.MediaBlock?.Video?.File?.VideoFile?.TranscriptFile?.File?.FilePath != null) + { + retVal.Add(oldblock.MediaBlock.Video.File.VideoFile.TranscriptFile.File.FilePath); + } + } + } + + var existingImages = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null).ToList(); + if (existingImages.Any()) + { + foreach (var oldblock in existingImages) + { + retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); + } + } + + var existingImageCarousel = allBlocks.Where(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null).ToList(); + if (existingImageCarousel.Any()) + { + foreach (var imageBlock in existingImageCarousel) + { + foreach (var oldblock in imageBlock.ImageCarouselBlock.ImageBlockCollection.Blocks) + { + retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); + } + } + } + + var existingWholeSlideImages = allBlocks.Where(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Any()).ToList(); + if (existingWholeSlideImages.Any()) + { + foreach (var wsi in existingWholeSlideImages) + { + foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems) + { + retVal.Add(oldblock.WholeSlideImage?.File?.FilePath); + } + } + } + } + + var questionFiles = this.CheckQuestionBlock(caseBlockCollection); + if (questionFiles.Any()) + { + retVal.AddRange(questionFiles); + } + } + + return retVal; + } + + private List CheckQuestionBlock(BlockCollectionViewModel model) + { + var filePath = new List(); + foreach (var block in model.Blocks) + { + if (block.BlockType == BlockType.Question && block.QuestionBlock != null) + { + if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) + { + foreach (var answerBlock in block.QuestionBlock.Answers) + { + if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null) + { + foreach (var imageBlock in answerBlock.BlockCollection.Blocks) + { + if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + { + filePath.Add(imageBlock.MediaBlock.Image.File.FilePath); + } + } + } + } + } + + var questionBlockCollection = block.QuestionBlock.QuestionBlockCollection; + if (questionBlockCollection != null && questionBlockCollection.Blocks != null) + { + foreach (var questionBlock in questionBlockCollection.Blocks) + { + if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) + { + if (questionBlock.MediaBlock.Image != null) + { + filePath.Add(questionBlock.MediaBlock.Image.File.FilePath); + } + + if (questionBlock.MediaBlock.Video != null) + { + if (questionBlock.MediaBlock.Video.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); + } + + if (questionBlock.MediaBlock.Video.VideoFile != null) + { + if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) + { + filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); + } + + if (questionBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + { + filePath.Add(questionBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + } + } + } + } + else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null) + { + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.ToList(); + if (existingWholeSlideImages.Any()) + { + foreach (var wsi in existingWholeSlideImages) + { + filePath.Add(wsi.WholeSlideImage?.File?.FilePath); + } + } + } + } + } + + var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; + if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null) + { + foreach (var feedbackBlock in feedbackBlockCollection.Blocks) + { + if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) + { + if (feedbackBlock.MediaBlock.Image != null) + { + filePath.Add(feedbackBlock.MediaBlock.Image.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video != null) + { + if (feedbackBlock.MediaBlock.Video.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video.VideoFile != null) + { + if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + } + } + } + } + } + } + } + } + + return filePath; + } } } \ No newline at end of file