diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 825914c97..6bfbcca6c 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -343,17 +343,17 @@ public ActionResult GetSettings() [Route("PublishResourceVersion")] public async Task PublishResourceVersionAsync([FromBody] PublishViewModel publishViewModel) { - var associatedResource = await this.resourceService.GetResourceVersionExtendedAsync(publishViewModel.ResourceVersionId); + var associatedResource = await this.resourceService.GetResourceVersionAsync(publishViewModel.ResourceVersionId); var validationResult = await this.contributeService.SubmitResourceVersionForPublishAsync(publishViewModel); if (validationResult.IsValid) { - if (associatedResource.ResourceTypeEnum != ResourceTypeEnum.Scorm && associatedResource.ResourceTypeEnum != ResourceTypeEnum.Html) + if (associatedResource.ResourceType != ResourceTypeEnum.Scorm && associatedResource.ResourceType != ResourceTypeEnum.Html) { - var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId); - if (obsoleteFiles != null && obsoleteFiles.Any()) - { - await this.fileService.PurgeResourceFile(null, obsoleteFiles); - } + var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId); + if (obsoleteFiles != null && obsoleteFiles.Any()) + { + await this.fileService.PurgeResourceFile(null, obsoleteFiles); + } } } @@ -738,10 +738,13 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems) { - var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any()); - if (entry == null) + if (oldblock != null && (oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingComplete || oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingFailed)) { - filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath); + var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any()); + if (entry == null) + { + filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath); + } } } } @@ -787,7 +790,7 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, deleteList); }); } } - catch (Exception ex) + catch { } } @@ -809,7 +812,7 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode { foreach (var imageBlock in answerBlock.BlockCollection.Blocks) { - if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null && imageBlock.MediaBlock.Image.File != null) { filePath.Add(imageBlock.MediaBlock.Image.File.FileId, imageBlock.MediaBlock.Image.File.FilePath); } @@ -832,13 +835,13 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode if (questionBlock.MediaBlock.Video != null) { - if (questionBlock.MediaBlock.Video.VideoFile != null) + if (questionBlock.MediaBlock.Video.File != null) { - if (questionBlock.MediaBlock.Video.File != null) - { - filePath.Add(questionBlock.MediaBlock.Video.File.FileId, questionBlock.MediaBlock.Video.File.FilePath); - } + filePath.Add(questionBlock.MediaBlock.Video.File.FileId, 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.FileId, questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); @@ -858,7 +861,7 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode { foreach (var wsi in existingWholeSlideImages) { - if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.WholeSlideImageFile != null && (wsi.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingComplete || wsi.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingFailed)) + if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.FileId > 0) { filePath.Add(wsi.WholeSlideImage.File.FileId, wsi.WholeSlideImage.File.FilePath); } @@ -882,13 +885,13 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode if (feedbackBlock.MediaBlock.Video != null) { - if (feedbackBlock.MediaBlock.Video.VideoFile != null) + if (feedbackBlock.MediaBlock.Video.File != null) { - if (feedbackBlock.MediaBlock.Video.File != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, feedbackBlock.MediaBlock.Video.File.FilePath); - } + filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, 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.FileId, feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql index 00b4aa351..fcf2e5a4a 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql @@ -7,6 +7,7 @@ -- Modification History -- -- 31-05-2024 TD-3023 Initial Revision +-- 04-06-2024 TD-3023 Included answer blocks to the search ------------------------------------------------------------------------------- @@ -93,6 +94,14 @@ END BlockCollectionId INT ); + DECLARE @QABlock TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + -- Table to hold results for blocks DECLARE @BlockResult TABLE ( Id INT, @@ -129,6 +138,20 @@ END INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id WHERE qb.Deleted = 0; + -- Insert answer question block data + INSERT INTO @QABlock + SELECT qb.Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + --Insert AnswerBlockcollectionId + INSERT INTO @BlockCollectionId (Id) + SELECT qa.BlockCollectionId + FROM resources.QuestionAnswer qa + INNER JOIN @QABlock b ON qa.QuestionBlockId = b.Id + WHERE qa.Deleted = 0; + -- Insert block data INSERT INTO @BlockResult @@ -344,6 +367,7 @@ END DECLARE @_QuestionBlockCollectionId TABLE (Id INT); DECLARE @_ImageCarouselBlockCollectionId TABLE (Id INT); DECLARE @_AllBlockAssociatedFiles TABLE (FileId INT, FilePath NVARCHAR(200)); + DECLARE @_QABlock TABLE (Id INT,[Order] INT,Title NVARCHAR(200),BlockType INT,BlockCollectionId INT); -- Insert BlockCollectionIds based on the provided query IF @resourceType = 10 @@ -443,7 +467,19 @@ END INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id WHERE qb.Deleted = 0; + -- Insert answer question block data + INSERT INTO @_QABlock + SELECT qb.Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + --Insert AnswerBlockcollectionId + INSERT INTO @_BlockCollectionId (Id) + SELECT qa.BlockCollectionId + FROM resources.QuestionAnswer qa + INNER JOIN @_QABlock b ON qa.QuestionBlockId = b.Id + WHERE qa.Deleted = 0; @@ -676,4 +712,4 @@ END ).value('.', 'NVARCHAR(MAX)'), 1, 2, ''); SET @filePath = @result; - END + END \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs index dc9ac9d94..c18b90187 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs @@ -438,73 +438,5 @@ private void SetAuditFieldsOnChildren(int userId, ImageCarouselBlock imageCarous this.SetAuditFieldsForCreateOrDelete(userId, imageCarouselBlock.ImageBlockCollection, isCreate); this.SetAuditFieldsOnChildren(userId, imageCarouselBlock.ImageBlockCollection, isCreate); } - - private async Task GetResourceBlockCollectionsFilePath(int excludeResourceVersionId) - { - var command = new SqlCommand - { - CommandType = CommandType.StoredProcedure, - CommandText = "[resources].[CaseBlockCollectionGetAll]", - Parameters = { new SqlParameter("@excludeResourceVersionId", SqlDbType.Int) { Value = excludeResourceVersionId } }, - }; - - var results = this.DbContext.MultipleResults(command) - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With