From 44a9d016db29a9eace2b7f2c8b99791ac788eec7 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Fri, 26 Apr 2024 16:46:37 +0100 Subject: [PATCH 01/31] TD-3023 refactor Case and assessment blockcollection obsolete file removal --- .../Controllers/Api/ContributeController.cs | 166 ++++++++- LearningHub.Nhs.WebUI/Services/FileService.cs | 40 --- .../ResourceService.cs | 338 ++++++++++++------ 3 files changed, 392 insertions(+), 152 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index a1716767a..6cf5fb7e8 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -493,7 +493,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 +510,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) + { + this.RemoveBlockCollectionFiles(existingResourceState.AssessmentDetails, request); + } + return this.Ok(resourceVersionId); } @@ -627,15 +637,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(); @@ -713,6 +736,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 +768,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..1dd2de510 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()) - { - 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()) + if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) { - foreach (var imageBlock in existingImageCarousel) + var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.EndGuidance); + if (assessmentFiles.Any()) { - 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()) + if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) { - foreach (var wsi in existingWholeSlideImages) + var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.AssessmentContent); + if (assessmentFiles.Any()) { - 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,192 @@ 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) + { + 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); + } + } + } + } + + 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 From 8aee4f30842947370da7a203242cdbca295274c3 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Fri, 26 Apr 2024 16:51:43 +0100 Subject: [PATCH 02/31] TD-3023 --- LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 6cf5fb7e8..1a43cd417 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -512,7 +512,7 @@ public async Task SaveAssessmentDetailAsync([FromBody] AssessmentV { var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); int resourceVersionId = await this.contributeService.SaveAssessmentDetailAsync(request); - if (existingResourceState != null) + if (existingResourceState != null && existingResourceState.AssessmentDetails != null) { this.RemoveBlockCollectionFiles(existingResourceState.AssessmentDetails, request); } From b7be45b07332a918a00897336585d247b796fea4 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Mon, 29 Apr 2024 09:26:43 +0100 Subject: [PATCH 03/31] TD-3023 video filepath update --- .../Controllers/Api/ContributeController.cs | 16 +++++++++++++--- .../LearningHub.Nhs.Services/ResourceService.cs | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 1a43cd417..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; @@ -682,10 +683,19 @@ private void RemoveBlockCollectionFiles(BlockCollectionViewModel existingResourc 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?.VideoFile?.TranscriptFile?.File?.FilePath); + filePaths.Add(oldblock.MediaBlock.Video.File.FilePath); + } + + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video?.File?.VideoFile?.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); } } } diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index 1dd2de510..7c7974798 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -4907,10 +4907,19 @@ private List CheckBlockFile(BlockCollectionViewModel model) { foreach (var oldblock in existingVideos) { - retVal.Add(oldblock.MediaBlock?.Video?.VideoFile?.File?.FilePath); - if (oldblock.MediaBlock?.Video?.VideoFile?.TranscriptFile?.File?.FilePath != null) + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video.File.FilePath)) { - retVal.Add(oldblock.MediaBlock.Video?.VideoFile?.TranscriptFile?.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); } } } From 9307479e953aaf1d191c6b73dd1c4e4cfa48d16c Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Mon, 29 Apr 2024 11:39:21 +0100 Subject: [PATCH 04/31] TD-4106: Issue with Formal assessments learning record showing as '0%' for completed, passed & failed assessments and showing date incorrect --- LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs | 4 ++-- .../Stored Procedures/Activity/GetUserLatestActivityCheck.sql | 2 +- .../Stored Procedures/Activity/GetUserLearningActivities.sql | 2 +- .../Activity/GetUserLearningActivitiesCount.sql | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs b/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs index f77383f0c..d23e0881e 100644 --- a/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs +++ b/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs @@ -226,7 +226,7 @@ public static string GetActivityStatusText(this ActivityDetailedItemViewModel ac /// The . public static bool CanShowScore(this ActivityDetailedItemViewModel activityDetailedItemViewModel) { - if ((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Scorm && (activityDetailedItemViewModel.MasteryScore > 0 || activityDetailedItemViewModel.MasteryScore == null) && ((activityDetailedItemViewModel.ScorePercentage > 0 && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Passed) || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Failed)) || ((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment || activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Case) && activityDetailedItemViewModel.Complete)) + if ((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Scorm && (activityDetailedItemViewModel.MasteryScore > 0 || activityDetailedItemViewModel.MasteryScore == null) && ((activityDetailedItemViewModel.ScorePercentage > 0 && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Passed) || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Failed)) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment && (activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Completed || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Passed || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Failed)) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Case && activityDetailedItemViewModel.Complete)) { return true; } @@ -241,7 +241,7 @@ public static bool CanShowScore(this ActivityDetailedItemViewModel activityDetai /// The bool. public static bool CanViewPercentage(this ActivityDetailedItemViewModel activityDetailedItemViewModel) { - if (((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Video || activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Audio) && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.InProgress) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment && activityDetailedItemViewModel.Complete == false)) + if (((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Video || activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Audio) && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.InProgress) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.InProgress)) { return true; } diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql index fdd97300c..2ae321439 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql @@ -162,7 +162,7 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5) ) ) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql index d8b8d3c5a..f1c121dba 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql @@ -230,7 +230,7 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5) ) ) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql index 0fff8bc1d..29d549dba 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql @@ -145,7 +145,7 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5) ) ) From 4c0dfc6284d22ac8392204fd9e1b40b16355ff14 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Tue, 30 Apr 2024 09:54:04 +0100 Subject: [PATCH 05/31] TD-4108: Certificate issue for assessment and audio/video has been resolved --- .../LearningHub.Nhs.Services/MyLearningService.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index de78a8738..55033501a 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -263,23 +263,16 @@ public async Task> PopulateMyLearningDetai ResourceActivity expectedActivity = null; if (resourceActivity.Resource.ResourceTypeEnum == ResourceTypeEnum.Audio || resourceActivity.Resource.ResourceTypeEnum == ResourceTypeEnum.Video) { - expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && x.MediaResourceActivity != null && x.MediaResourceActivity.Any(x => x.PercentComplete == 100)).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); + expectedActivity = latestActivityCheck.Where(x => x.LaunchResourceActivityId == resourceActivity.Id && resourceActivity.MediaResourceActivity != null && resourceActivity.MediaResourceActivity.Any(y => y.PercentComplete == 100)).OrderByDescending(y => y.ActivityStart).FirstOrDefault(); } else { - expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Launched) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); + expectedActivity = latestActivityCheck.Where(x => x.LaunchResourceActivityId == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Launched) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); } - if (latestActivityCheck.Any() && expectedActivity != null) + if (latestActivityCheck.Any() && expectedActivity != null && resourceActivity.ResourceVersion.CertificateEnabled == true) { - if (latestActivityCheck.OrderByDescending(x => x.ActivityStart).FirstOrDefault().Id == expectedActivity.Id) - { - viewModel.CertificateEnabled = resourceActivity.ResourceVersion.CertificateEnabled.GetValueOrDefault(false); - } - else - { - viewModel.CertificateEnabled = false; - } + viewModel.CertificateEnabled = true; } else { From 774d3c7c2c4c9f0c27fe01aa563a46073b9a3f07 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Tue, 30 Apr 2024 17:06:44 +0100 Subject: [PATCH 06/31] TD-4106: Doplicate record for assessment with dafault date issue resolved --- .../Activity/GetUserLatestActivityCheck.sql | 5 +++++ .../Stored Procedures/Activity/GetUserLearningActivities.sql | 5 +++++ .../Activity/GetUserLearningActivitiesCount.sql | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql index 2ae321439..99543b933 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql @@ -166,6 +166,11 @@ FROM ( ) ) + AND + ( + -- resource type is not assessment and activity status is Complete/Incomplete + [Res].[ResourceTypeId] <> 11 OR [ResourceActivity].[ActivityStatusId] in (7,3) + ) ) AS [t2] LEFT JOIN [resources].[VideoResourceVersion] AS [VideoResourceVersion] ON [t2].[Id1] = [VideoResourceVersion].[ResourceVersionId] diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql index f1c121dba..68d69fe64 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql @@ -234,6 +234,11 @@ FROM ( ) ) + AND + ( + -- resource type is not assessment and activity status is Complete/Incomplete + [Res].[ResourceTypeId] <> 11 OR [ResourceActivity].[ActivityStatusId] in (7,3) + ) AND ( @filterActivityStatus = 0 diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql index 29d549dba..16f18b122 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql @@ -149,6 +149,11 @@ FROM ( ) ) + AND + ( + -- resource type is not assessment and activity status is Complete/Incomplete + [Res].[ResourceTypeId] <> 11 OR [ResourceActivity].[ActivityStatusId] in (7,3) + ) AND ( @filterActivityStatus = 0 From 8b6871dc7d4ef9ba1e0a6e8bd806d707f66f383f Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Wed, 1 May 2024 15:26:26 +0100 Subject: [PATCH 07/31] TD-4108:Certficate issue for assessments resolved. Failed record not showing issue resolved. --- .../Stored Procedures/Activity/GetUserLatestActivityCheck.sql | 2 +- .../Stored Procedures/Activity/GetUserLearningActivities.sql | 2 +- .../Activity/GetUserLearningActivitiesCount.sql | 2 +- WebAPI/LearningHub.Nhs.Services/MyLearningService.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql index 99543b933..1e83fc9b8 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql @@ -162,7 +162,7 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5,4) ) ) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql index 68d69fe64..d44b645a4 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql @@ -230,7 +230,7 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5,4) ) ) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql index 16f18b122..8aa04ed0e 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql @@ -145,7 +145,7 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5,4) ) ) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index 55033501a..1f1b5dd55 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -267,7 +267,7 @@ public async Task> PopulateMyLearningDetai } else { - expectedActivity = latestActivityCheck.Where(x => x.LaunchResourceActivityId == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Launched) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); + expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Incomplete) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); } if (latestActivityCheck.Any() && expectedActivity != null && resourceActivity.ResourceVersion.CertificateEnabled == true) From c31cb9814e04caa9c474de04aab6d5e8976a5de2 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 2 May 2024 12:08:20 +0100 Subject: [PATCH 08/31] TD-4108: Fixed the issue with the certificate visibility --- WebAPI/LearningHub.Nhs.Services/MyLearningService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index 1f1b5dd55..9abbf2316 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -166,7 +166,7 @@ public async Task> GetResourceCertif activityQuery = activityQuery.Where(x => x.Resource.ResourceReference.FirstOrDefault() != null && x.Resource.ResourceReference.Any(rr => rr.OriginalResourceReferenceId == resourceReferenceId)); int totalNumberOfAccess = activityQuery.Count(); var activityEntities = await activityQuery.OrderByDescending(x => x.Score).ThenByDescending(x => x.ActivityStart).ToListAsync(); - activityEntities.RemoveAll(x => x.Resource.ResourceTypeEnum == ResourceTypeEnum.Scorm && (x.ActivityStatusId == (int)ActivityStatusEnum.Downloaded || x.ActivityStatusId == (int)ActivityStatusEnum.Launched || x.ActivityStatusId == (int)ActivityStatusEnum.InProgress)); + activityEntities.RemoveAll(x => x.Resource.ResourceTypeEnum == ResourceTypeEnum.Scorm && (x.ActivityStatusId == (int)ActivityStatusEnum.Downloaded || x.ActivityStatusId == (int)ActivityStatusEnum.Incomplete || x.ActivityStatusId == (int)ActivityStatusEnum.InProgress)); if (activityEntities.Any() && activityEntities.FirstOrDefault()?.Resource.ResourceTypeEnum == ResourceTypeEnum.Assessment) { activityEntities = activityEntities.Where(x => x.AssessmentResourceActivity.FirstOrDefault() != null && x.AssessmentResourceActivity.FirstOrDefault().Score.HasValue && ((int)Math.Round(x.AssessmentResourceActivity.FirstOrDefault().Score.Value, MidpointRounding.AwayFromZero) >= x.ResourceVersion.AssessmentResourceVersion.PassMark)).ToList(); @@ -181,7 +181,7 @@ public async Task> GetResourceCertif } else { - filteredActivity = activityEntities.Where(x => x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Launched) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded)).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); + filteredActivity = activityEntities.Where(x => x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Incomplete) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded)).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); } if (filteredActivity != null) From 6de6bb054b643b587fdf304344254bd59ba292e5 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 2 May 2024 13:35:05 +0100 Subject: [PATCH 09/31] TD-4115 - Issues on showing statuses on 'My accessed Learning' --- .../Stored Procedures/Resources/GetDashboardResources.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index 194eb9dac..e24008aa6 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -17,6 +17,7 @@ -- 08 Nov 2023 OA Fixed latest resource activity entry selection(with updated logic for media activities) and status check for incomplete assessment. -- 17 Jan 2024 SA Changes to accomadate activity status changes -- 27 Feb 2024 SS Fixed missing In progress resources in the My Accessed Learning tray issue +-- 2 May 2024 SA Fixed the issue on showing statuses on 'My accessed Learning' for resource type file ------------------------------------------------------------------------------- CREATE PROCEDURE [resources].[GetDashboardResources] @@ -237,7 +238,7 @@ BEGIN (r.ResourceTypeId IN (1, 5, 8, 9,10, 12) AND ra.ActivityStatusId <> 3) OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) - OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (6)) + OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (3)) OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (1))) ) GROUP BY ra.ResourceId From e2c475fc401c8050548a3dcacb074fab746baf10 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 2 May 2024 16:01:02 +0100 Subject: [PATCH 10/31] =?UTF-8?q?TD-4115:=20Issue=203=20-=20Contributed=20?= =?UTF-8?q?to=20=E2=80=98Formal=20assessment=E2=80=99=20slide=20viewer=20i?= =?UTF-8?q?mage=20in=20some=20catalogue=20Published=20the=20resource=20eve?= =?UTF-8?q?n=20though=20the=20resource=20is=20still=20processing.=20When?= =?UTF-8?q?=20viewed=20the=20resource=20can=20see=20still=20the=20slide=20?= =?UTF-8?q?is=20not=20ready.=20And,=20on=20=E2=80=98My=20Learning=E2=80=99?= =?UTF-8?q?=20page,=20can=20see=20status=20as=20=E2=80=98In=20progress?= =?UTF-8?q?=E2=80=99.=20But,=20I=20don=E2=80=99t=20see=20this=20record=20o?= =?UTF-8?q?f=20resource=20on=20=E2=80=98In=20progress=E2=80=99=20section?= =?UTF-8?q?=20on=20=E2=80=98My=20accessed=20Learning=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Stored Procedures/Resources/GetDashboardResources.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index e24008aa6..0c84f4a44 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -239,7 +239,7 @@ BEGIN OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (3)) - OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (1))) + OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (7))) ) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC From 7119a8196bb5e038b4dce8893247e248658160dd Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 2 May 2024 16:07:17 +0100 Subject: [PATCH 11/31] Modified --- .../Stored Procedures/Resources/GetDashboardResources.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index 0c84f4a44..c794f8d89 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -239,7 +239,7 @@ BEGIN OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (3)) - OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (7))) + OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId = 7)) ) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC From b00b63df42ab20e538de9ca00fb477625b41268f Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 2 May 2024 17:22:51 +0100 Subject: [PATCH 12/31] TD-4016: Issue with informal assessment duplicate record while searching --- .../Activity/GetUserLearningActivities.sql | 6 +++--- .../Activity/GetUserLearningActivitiesCount.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql index d44b645a4..c96931937 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql @@ -175,7 +175,7 @@ FROM ( @searchText IS NULL OR ( - Charindex(@searchText, [ResVer].[Title]) > 0 + (Charindex(@searchText, [ResVer].[Title]) > 0 OR Charindex(@searchText, [ResVer].[Description]) > 0 OR @@ -189,8 +189,8 @@ FROM ( [ResVer].[Id] = [ResourceVersionKeyword].[ResourceVersionId] AND Charindex(@searchText, [ResourceVersionKeyword].[Keyword]) > 0 - ) - ) + ) + )) AND [ResourceActivity].ActivityStart is not null ) ) AND diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql index 8aa04ed0e..daa20e0e7 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql @@ -90,7 +90,7 @@ FROM ( @searchText IS NULL OR ( - Charindex(@searchText, [ResVer].[Title]) > 0 + (Charindex(@searchText, [ResVer].[Title]) > 0 OR Charindex(@searchText, [ResVer].[Description]) > 0 OR @@ -104,8 +104,8 @@ FROM ( [ResVer].[Id] = [ResourceVersionKeyword].[ResourceVersionId] AND Charindex(@searchText, [ResourceVersionKeyword].[Keyword]) > 0 - ) - ) + ) + )) AND [ResourceActivity].ActivityStart is not null ) ) AND From 2468b06217ade808366e0410a5f110de78e2a921 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Fri, 3 May 2024 12:43:04 +0100 Subject: [PATCH 13/31] TD-4115 - Number of accessed showing incorrect in the certificate details --- WebAPI/LearningHub.Nhs.Services/MyLearningService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index 9abbf2316..13e28cb9d 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -169,8 +169,13 @@ public async Task> GetResourceCertif activityEntities.RemoveAll(x => x.Resource.ResourceTypeEnum == ResourceTypeEnum.Scorm && (x.ActivityStatusId == (int)ActivityStatusEnum.Downloaded || x.ActivityStatusId == (int)ActivityStatusEnum.Incomplete || x.ActivityStatusId == (int)ActivityStatusEnum.InProgress)); if (activityEntities.Any() && activityEntities.FirstOrDefault()?.Resource.ResourceTypeEnum == ResourceTypeEnum.Assessment) { + totalNumberOfAccess = activityQuery.SelectMany(x => x.AssessmentResourceActivity).OrderByDescending(a => a.CreateDate).ToList().Count(); activityEntities = activityEntities.Where(x => x.AssessmentResourceActivity.FirstOrDefault() != null && x.AssessmentResourceActivity.FirstOrDefault().Score.HasValue && ((int)Math.Round(x.AssessmentResourceActivity.FirstOrDefault().Score.Value, MidpointRounding.AwayFromZero) >= x.ResourceVersion.AssessmentResourceVersion.PassMark)).ToList(); } + else if (activityEntities.Any() && (activityEntities.FirstOrDefault()?.Resource.ResourceTypeEnum == ResourceTypeEnum.Video || activityEntities.FirstOrDefault()?.Resource.ResourceTypeEnum == ResourceTypeEnum.Audio)) + { + totalNumberOfAccess = activityQuery.SelectMany(x => x.MediaResourceActivity).OrderByDescending(a => a.CreateDate).ToList().Count(); + } if (activityEntities.Any()) { @@ -272,7 +277,7 @@ public async Task> PopulateMyLearningDetai if (latestActivityCheck.Any() && expectedActivity != null && resourceActivity.ResourceVersion.CertificateEnabled == true) { - viewModel.CertificateEnabled = true; + viewModel.CertificateEnabled = true; } else { @@ -490,7 +495,7 @@ private IQueryable ApplyFilters(IQueryable q if (requestModel.CertificateEnabled) { - query = query.Where(x => x.ResourceVersion.CertificateEnabled.Equals(true)); + query = query.Where(x => x.ResourceVersion.CertificateEnabled.Equals(true)); } return query; From ef7ebe97b040483f38a62fb580b43a7b54a07c21 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Tue, 7 May 2024 09:25:13 +0100 Subject: [PATCH 14/31] TD-3023 fix for deleted blocks which are valid in an active published resource version --- .../Controllers/Api/ContributeController.cs | 39 ++++++--- .../ResourceService.cs | 83 +++++++++++++------ 2 files changed, 86 insertions(+), 36 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 63c251451..887e4bd04 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -496,7 +496,7 @@ public async Task SaveCaseDetailAsync([FromBody] CaseViewModel req int resourceVersionId = await this.contributeService.SaveCaseDetailAsync(request); if (existingResourceState.CaseDetails?.BlockCollection != null) { - this.RemoveBlockCollectionFiles(existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); + await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); } return this.Ok(resourceVersionId); @@ -515,7 +515,7 @@ public async Task SaveAssessmentDetailAsync([FromBody] AssessmentV int resourceVersionId = await this.contributeService.SaveAssessmentDetailAsync(request); if (existingResourceState != null && existingResourceState.AssessmentDetails != null) { - this.RemoveBlockCollectionFiles(existingResourceState.AssessmentDetails, request); + await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.AssessmentDetails, request); } return this.Ok(resourceVersionId); @@ -638,23 +638,24 @@ private async Task UserCanEditCatalogue(int catalogueId) return await this.catalogueService.CanCurrentUserEditCatalogue(catalogueId); } - private void RemoveBlockCollectionFiles(AssessmentViewModel existingModel, AssessmentViewModel newModel) + private async Task RemoveBlockCollectionFiles(int resourceVersionId, AssessmentViewModel existingModel, AssessmentViewModel newModel) { if (existingModel is { EndGuidance: { } } && existingModel.EndGuidance.Blocks != null) { - this.RemoveBlockCollectionFiles(existingModel.EndGuidance, newModel.EndGuidance); + await this.RemoveBlockCollectionFiles(resourceVersionId, existingModel.EndGuidance, newModel.EndGuidance); } if (existingModel is { AssessmentContent: { } } && existingModel.AssessmentContent.Blocks != null) { - this.RemoveBlockCollectionFiles(existingModel.AssessmentContent, newModel.AssessmentContent); + await this.RemoveBlockCollectionFiles(resourceVersionId, existingModel.AssessmentContent, newModel.AssessmentContent); } } - private void RemoveBlockCollectionFiles(BlockCollectionViewModel existingResource, BlockCollectionViewModel newResource) + private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollectionViewModel existingResource, BlockCollectionViewModel newResource) { try { + var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(resourceVersionId, true); var filePaths = new List(); if (existingResource != null) { @@ -706,8 +707,8 @@ private void RemoveBlockCollectionFiles(BlockCollectionViewModel existingResourc { foreach (var oldblock in existingImages) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId); - if (entry == null) + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId); + if (entry == null) { filePaths.Add(oldblock?.MediaBlock?.Image?.File?.FilePath); } @@ -771,7 +772,18 @@ private void RemoveBlockCollectionFiles(BlockCollectionViewModel existingResourc if (filePaths != null && filePaths.Any()) { - _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); }); + var deleteList = new List(); + foreach (var e in filePaths) + { + if (!obsoleteFiles.Contains(e)) + { + continue; + } + + deleteList.Add(e); + } + + _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, deleteList); }); } } catch (Exception ex) @@ -838,12 +850,15 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) } else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null) { - var existingWholeSlideImages = questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.ToList(); - if (existingWholeSlideImages.Any()) + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock?.WholeSlideImageBlockItems; + if (existingWholeSlideImages != null && existingWholeSlideImages.Any()) { foreach (var wsi in existingWholeSlideImages) { - filePath.Add(wsi.WholeSlideImage?.File?.FilePath); + if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null) + { + filePath.Add(wsi.WholeSlideImage.File.FilePath); + } } } } diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index 7c7974798..c0b7e5d1f 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -1477,7 +1477,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b { if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) { - var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.EndGuidance); + var assessmentFiles = this.CheckBlockFile(extendedResourceVersion.AssessmentDetails.EndGuidance, resource.AssessmentDetails.EndGuidance); if (assessmentFiles.Any()) { retVal.AddRange(assessmentFiles); @@ -1486,7 +1486,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) { - var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.AssessmentContent); + var assessmentFiles = this.CheckBlockFile(extendedResourceVersion.AssessmentDetails.AssessmentContent, resource.AssessmentDetails.AssessmentContent); if (assessmentFiles.Any()) { retVal.AddRange(assessmentFiles); @@ -1498,7 +1498,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b { if (deletedResource) { - var caseFiles = this.CheckBlockFile(resource.CaseDetails.BlockCollection); + var caseFiles = this.CheckBlockFile(extendedResourceVersion.CaseDetails.BlockCollection, resource.CaseDetails.BlockCollection); if (caseFiles.Any()) { retVal.AddRange(caseFiles); @@ -1557,7 +1557,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b { if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) { - var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.EndGuidance); + var assessmentFiles = this.CheckBlockFile(null, resource.AssessmentDetails.EndGuidance); if (assessmentFiles.Any()) { retVal.AddRange(assessmentFiles); @@ -1566,7 +1566,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) { - var assessmentFiles = this.CheckBlockFile(resource.AssessmentDetails.AssessmentContent); + var assessmentFiles = this.CheckBlockFile(null, resource.AssessmentDetails.AssessmentContent); if (assessmentFiles.Any()) { retVal.AddRange(assessmentFiles); @@ -1576,7 +1576,7 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b } else if (resource.ResourceTypeEnum == ResourceTypeEnum.Case) { - var caseFiles = this.CheckBlockFile(resource.CaseDetails.BlockCollection); + var caseFiles = this.CheckBlockFile(null, resource.CaseDetails.BlockCollection); if (caseFiles.Any()) { retVal.AddRange(caseFiles); @@ -4884,7 +4884,7 @@ private async Task CreateNewResource(ResourceTypeEnum resourceType, string return resourceVersionId; } - private List CheckBlockFile(BlockCollectionViewModel model) + private List CheckBlockFile(BlockCollectionViewModel? publishedBlock, BlockCollectionViewModel model) { var retVal = new List(); var caseBlockCollection = model; @@ -4898,7 +4898,11 @@ private List CheckBlockFile(BlockCollectionViewModel model) { foreach (var oldblock in existingAttachements) { - retVal.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); + var publishedEntry = (publishedBlock != null && publishedBlock.Blocks.Any()) ? publishedBlock.Blocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null && x.MediaBlock.Attachment.File?.FileId == oldblock.MediaBlock.Attachment?.File?.FileId) : null; + if (publishedEntry == null) + { + retVal.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); + } } } @@ -4907,19 +4911,23 @@ private List CheckBlockFile(BlockCollectionViewModel model) { foreach (var oldblock in existingVideos) { - if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video.File.FilePath)) + var publishedEntry = (publishedBlock != null && publishedBlock.Blocks.Any()) ? publishedBlock.Blocks.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) : null; + if (publishedEntry == null) { - retVal.Add(oldblock.MediaBlock.Video.File.FilePath); - } + 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 (!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); + if (oldblock.MediaBlock?.Video?.File?.VideoFile?.TranscriptFile?.File?.FilePath != null) + { + retVal.Add(oldblock.MediaBlock.Video.File.VideoFile.TranscriptFile.File.FilePath); + } } } } @@ -4929,7 +4937,11 @@ private List CheckBlockFile(BlockCollectionViewModel model) { foreach (var oldblock in existingImages) { - retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); + var publishedEntry = (publishedBlock != null && publishedBlock.Blocks.Any()) ? publishedBlock.Blocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId) : null; + if (publishedEntry == null) + { + retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); + } } } @@ -4940,7 +4952,11 @@ private List CheckBlockFile(BlockCollectionViewModel model) { foreach (var oldblock in imageBlock.ImageCarouselBlock.ImageBlockCollection.Blocks) { - retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); + var publishedEntry = (publishedBlock != null && publishedBlock.Blocks.Any()) ? publishedBlock.Blocks.FirstOrDefault(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks.Where(x => x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId).Any()) : null; + if (publishedEntry == null) + { + retVal.Add(oldblock.MediaBlock?.Image?.File?.FilePath); + } } } } @@ -4952,17 +4968,33 @@ private List CheckBlockFile(BlockCollectionViewModel model) { foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems) { - retVal.Add(oldblock.WholeSlideImage?.File?.FilePath); + var publishedEntry = (publishedBlock != null && publishedBlock.Blocks.Any()) ? publishedBlock.Blocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId).Any()) : null; + if (publishedEntry == null) + { + retVal.Add(oldblock.WholeSlideImage?.File?.FilePath); + } } } } } var questionFiles = this.CheckQuestionBlock(caseBlockCollection); - if (questionFiles.Any()) + var publishedQuestionFiles = (publishedBlock != null && publishedBlock.Blocks.Any()) ? this.CheckQuestionBlock(publishedBlock) : new List(); + if (questionFiles.Any() && !publishedQuestionFiles.Any()) { retVal.AddRange(questionFiles); } + else if (questionFiles.Any() && publishedQuestionFiles.Any()) + { + foreach (var file in questionFiles) + { + var publishedEntry = publishedQuestionFiles.FirstOrDefault(x => x.Equals(file)); + if (publishedEntry == null) + { + retVal.Add(file); + } + } + } } return retVal; @@ -5027,12 +5059,15 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) } else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null) { - var existingWholeSlideImages = questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.ToList(); + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems; if (existingWholeSlideImages.Any()) { foreach (var wsi in existingWholeSlideImages) { - filePath.Add(wsi.WholeSlideImage?.File?.FilePath); + if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null) + { + filePath.Add(wsi.WholeSlideImage.File.FilePath); + } } } } From 26abd616793c6bc9dd3fee3c41df9e5915a51297 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Tue, 7 May 2024 10:41:02 +0100 Subject: [PATCH 15/31] TD-3023 check for obsolete files before saving new block collection. --- .../Controllers/Api/ContributeController.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 887e4bd04..5eeca7be7 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -493,12 +493,12 @@ public async Task SaveWeblinkDetailAsync([FromBody] WebLinkViewMod public async Task SaveCaseDetailAsync([FromBody] CaseViewModel request) { var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); - int resourceVersionId = await this.contributeService.SaveCaseDetailAsync(request); if (existingResourceState.CaseDetails?.BlockCollection != null) { - await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); + await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); } + int resourceVersionId = await this.contributeService.SaveCaseDetailAsync(request); return this.Ok(resourceVersionId); } @@ -512,12 +512,12 @@ public async Task SaveCaseDetailAsync([FromBody] CaseViewModel req 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) { - await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.AssessmentDetails, request); + await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.AssessmentDetails, request); } + int resourceVersionId = await this.contributeService.SaveAssessmentDetailAsync(request); return this.Ok(resourceVersionId); } From db74a91df2dddbd04c68c37f706e2e8eb8c17f12 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Tue, 7 May 2024 11:37:15 +0100 Subject: [PATCH 16/31] TD-4115: Fixes for the my learning tray in progress activities --- .../Stored Procedures/Resources/GetDashboardResources.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index c794f8d89..4fc44526b 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -226,7 +226,7 @@ BEGIN INSERT INTO @MyActivity SELECT TOP (@MaxRows) ra.ResourceId, MAX(ra.Id) ResourceActivityId FROM - (SELECT a.* FROM activity.ResourceActivity a INNER JOIN (SELECT ResourceId, MAX(Id) as id FROM activity.ResourceActivity GROUP BY ResourceId,ActivityStatusId ) AS b ON a.ResourceId = b.ResourceId AND a.id = b.id order by a.Id desc OFFSET 0 ROWS) ra + (SELECT a.* FROM activity.ResourceActivity a INNER JOIN (SELECT ResourceId, MAX(Id) as id FROM activity.ResourceActivity GROUP BY ResourceId) AS b ON a.ResourceId = b.ResourceId AND a.id = b.id order by a.Id desc OFFSET 0 ROWS) ra JOIN [resources].[Resource] r ON ra.ResourceId = r.Id JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId LEFT JOIN [resources].[AssessmentResourceVersion] arv ON arv.ResourceVersionId = ra.ResourceVersionId @@ -238,7 +238,6 @@ BEGIN (r.ResourceTypeId IN (1, 5, 8, 9,10, 12) AND ra.ActivityStatusId <> 3) OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) - OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (3)) OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId = 7)) ) GROUP BY ra.ResourceId From 72ea324bb90542a00876feadd7610b899171c991 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 9 May 2024 15:54:35 +0100 Subject: [PATCH 17/31] TD-4121: LH-Issue with 'View certificate' link showing for all the completed entries instead showing for the latest completed record --- .../LearningHub.Nhs.Services/MyLearningService.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index 13e28cb9d..47e20ce28 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -275,9 +275,19 @@ public async Task> PopulateMyLearningDetai expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Incomplete) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); } - if (latestActivityCheck.Any() && expectedActivity != null && resourceActivity.ResourceVersion.CertificateEnabled == true) + if (latestActivityCheck.Any() && expectedActivity != null) { - viewModel.CertificateEnabled = true; + bool isExpectedActivityIdMatched = false; + if (resourceActivity.Resource.ResourceTypeEnum == ResourceTypeEnum.Audio || resourceActivity.Resource.ResourceTypeEnum == ResourceTypeEnum.Video) + { + isExpectedActivityIdMatched = latestActivityCheck.OrderByDescending(x => x.ActivityStart).FirstOrDefault().Id == expectedActivity.LaunchResourceActivityId; + } + else + { + isExpectedActivityIdMatched = latestActivityCheck.OrderByDescending(x => x.ActivityStart).FirstOrDefault().Id == expectedActivity.Id; + } + + viewModel.CertificateEnabled = isExpectedActivityIdMatched && resourceActivity.ResourceVersion.CertificateEnabled.GetValueOrDefault(false); } else { From b9e1eebc20c7827d10b61a4c547a032f7974a260 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Thu, 9 May 2024 17:02:57 +0100 Subject: [PATCH 18/31] Removed unwanted condition --- WebAPI/LearningHub.Nhs.Services/MyLearningService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index 47e20ce28..57935ad36 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -272,7 +272,7 @@ public async Task> PopulateMyLearningDetai } else { - expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Incomplete) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); + expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); } if (latestActivityCheck.Any() && expectedActivity != null) From 3f711aee6d44ecd23b4a04e8f2b6c183104bae87 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Fri, 10 May 2024 15:03:18 +0100 Subject: [PATCH 19/31] TD-4121: Fixed the issue with the assessment certificate view --- WebAPI/LearningHub.Nhs.Services/MyLearningService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs index 57935ad36..47e20ce28 100644 --- a/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs +++ b/WebAPI/LearningHub.Nhs.Services/MyLearningService.cs @@ -272,7 +272,7 @@ public async Task> PopulateMyLearningDetai } else { - expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); + expectedActivity = latestActivityCheck.Where(x => x.Id == resourceActivity.Id && (x.ActivityStatusId == ((int)ActivityStatusEnum.Completed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Incomplete) || x.ActivityStatusId == ((int)ActivityStatusEnum.Passed) || x.ActivityStatusId == ((int)ActivityStatusEnum.Downloaded))).OrderByDescending(x => x.ActivityStart).FirstOrDefault(); } if (latestActivityCheck.Any() && expectedActivity != null) From 6bb737d6ab558f5e39fb8794e17970d4a03e84c4 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Fri, 10 May 2024 16:05:04 +0100 Subject: [PATCH 20/31] TD-3023 QuestionBlock wsi bugfix and draft published case file --- .../Controllers/Api/ContributeController.cs | 4 +- .../ResourceService.cs | 62 +++++++++++++------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 5eeca7be7..09ffdc6bb 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -493,7 +493,7 @@ public async Task SaveWeblinkDetailAsync([FromBody] WebLinkViewMod public async Task SaveCaseDetailAsync([FromBody] CaseViewModel request) { var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); - if (existingResourceState.CaseDetails?.BlockCollection != null) + if (existingResourceState?.CaseDetails?.BlockCollection != null) { await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); } @@ -903,7 +903,7 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) } } - return filePath; + return filePath.Where(x => x != null).ToList(); } } } diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index c0b7e5d1f..e040a21c8 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -1471,38 +1471,60 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b } } } - else if (resource.ResourceTypeEnum == ResourceTypeEnum.Assessment) + else if (extendedResourceVersion.ResourceTypeEnum == ResourceTypeEnum.Assessment) { - if (deletedResource) - { - if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) + var endGuidanceFiles = new List(); + var assessmentContentFiles = new List(); + + if (resource.AssessmentDetails is { EndGuidance: { } } && resource.AssessmentDetails.EndGuidance.Blocks != null) { - var assessmentFiles = this.CheckBlockFile(extendedResourceVersion.AssessmentDetails.EndGuidance, resource.AssessmentDetails.EndGuidance); - if (assessmentFiles.Any()) + if (deletedResource) { - retVal.AddRange(assessmentFiles); + endGuidanceFiles = this.CheckBlockFile(extendedResourceVersion.AssessmentDetails.EndGuidance, resource.AssessmentDetails.EndGuidance); + } + else + { + endGuidanceFiles = this.CheckBlockFile(resource.AssessmentDetails.EndGuidance, extendedResourceVersion.AssessmentDetails.EndGuidance); + } + + if (endGuidanceFiles.Any()) + { + retVal.AddRange(endGuidanceFiles); } } - if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) + if (resource.AssessmentDetails is { AssessmentContent: { } } && resource.AssessmentDetails.AssessmentContent.Blocks != null) { - var assessmentFiles = this.CheckBlockFile(extendedResourceVersion.AssessmentDetails.AssessmentContent, resource.AssessmentDetails.AssessmentContent); - if (assessmentFiles.Any()) + if (deletedResource) { - retVal.AddRange(assessmentFiles); + assessmentContentFiles = this.CheckBlockFile(extendedResourceVersion.AssessmentDetails.AssessmentContent, resource.AssessmentDetails.AssessmentContent); + } + else + { + assessmentContentFiles = this.CheckBlockFile(resource.AssessmentDetails.AssessmentContent, extendedResourceVersion.AssessmentDetails.AssessmentContent); + } + + if (assessmentContentFiles.Any()) + { + retVal.AddRange(assessmentContentFiles); } } - } } - else if (resource.ResourceTypeEnum == ResourceTypeEnum.Case) + else if (extendedResourceVersion.ResourceTypeEnum == ResourceTypeEnum.Case) { + var caseFiles = new List(); if (deletedResource) { - var caseFiles = this.CheckBlockFile(extendedResourceVersion.CaseDetails.BlockCollection, resource.CaseDetails.BlockCollection); - if (caseFiles.Any()) - { - retVal.AddRange(caseFiles); - } + caseFiles = this.CheckBlockFile(extendedResourceVersion.CaseDetails.BlockCollection, resource.CaseDetails.BlockCollection); + } + else + { + caseFiles = this.CheckBlockFile(resource.CaseDetails.BlockCollection, extendedResourceVersion.CaseDetails.BlockCollection); + } + + if (caseFiles.Any()) + { + retVal.AddRange(caseFiles); } } } @@ -4997,7 +5019,7 @@ private List CheckBlockFile(BlockCollectionViewModel? publishedBlock, Bl } } - return retVal; + return retVal.Where(x => x != null).ToList(); } private List CheckQuestionBlock(BlockCollectionViewModel model) @@ -5112,7 +5134,7 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) } } - return filePath; + return filePath.Where(x => x != null).ToList(); } } } \ No newline at end of file From 6f63913f393814da8e08a15f8c3ac438627d40a7 Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Mon, 13 May 2024 10:48:51 +0100 Subject: [PATCH 21/31] TD-4115: Issues on showing statuses on 'My accessed Learning' section of Learning Hub Home page --- .../Resources/GetDashboardResources.sql | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index 4fc44526b..1618e5af4 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -18,6 +18,7 @@ -- 17 Jan 2024 SA Changes to accomadate activity status changes -- 27 Feb 2024 SS Fixed missing In progress resources in the My Accessed Learning tray issue -- 2 May 2024 SA Fixed the issue on showing statuses on 'My accessed Learning' for resource type file +-- 13 May 2024 SA TD-4115 ------------------------------------------------------------------------------- CREATE PROCEDURE [resources].[GetDashboardResources] @@ -238,11 +239,13 @@ BEGIN (r.ResourceTypeId IN (1, 5, 8, 9,10, 12) AND ra.ActivityStatusId <> 3) OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) - OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId = 7)) + OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (3)) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 2) AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (7))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 1) AND ra.ActivityStatusId IN (7)) ) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC - + SELECT ma.ResourceActivityId, r.Id AS ResourceId ,( SELECT TOP 1 rr.OriginalResourceReferenceId FROM [resources].[ResourceReference] rr @@ -384,7 +387,8 @@ BEGIN AND ( (r.ResourceTypeId IN (2, 7) AND ra.ActivityStatusId IN (3) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00' OR mar.Id IS NOT NULL AND mar.PercentComplete = 100) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status IN(3,5) OR (ra.ActivityStatusId IN(3, 5)))) - OR (r.ResourceTypeId = 11 AND ara.Score >= arv.PassMark OR ra.ActivityStatusId IN(3, 5)) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 2) AND (ara.Score >= arv.PassMark OR ra.ActivityStatusId IN(3, 5))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType =1) AND (ara.Score >= arv.PassMark AND ra.ActivityStatusId IN(3, 5))) OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId IN (3))) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC From 1d54f60983c8a78d6c48888d7c88d593f034ea26 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Mon, 13 May 2024 15:37:02 +0100 Subject: [PATCH 22/31] TD-4115- My accessed learning tray issues --- .../Resources/GetDashboardResources.sql | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index 1618e5af4..0a5da6e56 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -239,9 +239,8 @@ BEGIN (r.ResourceTypeId IN (1, 5, 8, 9,10, 12) AND ra.ActivityStatusId <> 3) OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) - OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (3)) OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 2) AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (7))) - OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 1) AND ra.ActivityStatusId IN (7)) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 1) AND ra.ActivityStatusId = 7) ) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC @@ -315,7 +314,7 @@ BEGIN (r.ResourceTypeId IN (2, 7) AND ra.ActivityStatusId IN (3) AND ((mar.Id IS NOT NULL AND mar.PercentComplete = 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status IN(3,5) OR (ra.ActivityStatusId IN(3, 5)))) OR (r.ResourceTypeId = 11 AND ara.Score >= arv.PassMark OR ra.ActivityStatusId IN( 3, 5)) - OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId IN (3))) + OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId = 3)) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC @@ -388,8 +387,8 @@ BEGIN (r.ResourceTypeId IN (2, 7) AND ra.ActivityStatusId IN (3) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00' OR mar.Id IS NOT NULL AND mar.PercentComplete = 100) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status IN(3,5) OR (ra.ActivityStatusId IN(3, 5)))) OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 2) AND (ara.Score >= arv.PassMark OR ra.ActivityStatusId IN(3, 5))) - OR ((r.ResourceTypeId = 11 AND arv.AssessmentType =1) AND (ara.Score >= arv.PassMark AND ra.ActivityStatusId IN(3, 5))) - OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId IN (3))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType =1) AND (ara.Score >= arv.PassMark AND ra.ActivityStatusId IN(3, 5,7))) + OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId = 3)) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC From bd8700c8593337d9beb8da9a70bb6d2c7b16a8a7 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Tue, 14 May 2024 12:07:10 +0100 Subject: [PATCH 23/31] TD-3023 Iuuse with video and swi in question block --- .../Controllers/Api/ContributeController.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 09ffdc6bb..57fa075d3 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -829,13 +829,13 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) 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.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); + } + if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); @@ -855,7 +855,7 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) { foreach (var wsi in existingWholeSlideImages) { - if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null) + if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.WholeSlideImageFile != null) { filePath.Add(wsi.WholeSlideImage.File.FilePath); } @@ -879,13 +879,13 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) 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.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); + } + if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); From db31b6ecb92394af25aa79d32b07dcbfd7644e23 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Tue, 14 May 2024 14:12:00 +0100 Subject: [PATCH 24/31] TD-3023 Delete empty folder --- LearningHub.Nhs.WebUI/Services/FileService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LearningHub.Nhs.WebUI/Services/FileService.cs b/LearningHub.Nhs.WebUI/Services/FileService.cs index 0e6fce092..4e02db124 100644 --- a/LearningHub.Nhs.WebUI/Services/FileService.cs +++ b/LearningHub.Nhs.WebUI/Services/FileService.cs @@ -309,7 +309,7 @@ private async Task MoveOutPutDirectoryToArchive(List allDirectoryRef) } } - await directory.DeleteAsync(); + await directory.DeleteIfExistsAsync(); } } } @@ -365,6 +365,8 @@ private async Task DeleteSubdirectory(string pathDirectory) await sourceFileClient.DeleteIfExistsAsync(); } } + + await sourceDirectory.DeleteIfExistsAsync(); } private async Task MoveInPutDirectoryToArchive(List allDirectoryRef) From f9a523f1bbae1c9312230624b70787310cd9f0c1 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Tue, 14 May 2024 16:15:13 +0100 Subject: [PATCH 25/31] TD-3023 wsi null filter --- .../ResourceService.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index e040a21c8..68342eda7 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -5060,13 +5060,13 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) 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.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); + } + if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); @@ -5086,7 +5086,7 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) { foreach (var wsi in existingWholeSlideImages) { - if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null) + if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.WholeSlideImageFile != null) { filePath.Add(wsi.WholeSlideImage.File.FilePath); } @@ -5110,13 +5110,13 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) 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.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); + } + if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); From 42b06cb7aa3a1d6139967f26bce774267e2f80fc Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Wed, 15 May 2024 11:56:02 +0100 Subject: [PATCH 26/31] TD-3023 exclude wsi that are still processing. --- LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs | 2 +- WebAPI/LearningHub.Nhs.Services/ResourceService.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 57fa075d3..b5c555b08 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -855,7 +855,7 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) { foreach (var wsi in existingWholeSlideImages) { - if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.WholeSlideImageFile != null) + 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)) { filePath.Add(wsi.WholeSlideImage.File.FilePath); } diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index 68342eda7..67f233123 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -29,6 +29,7 @@ namespace LearningHub.Nhs.Services using LearningHub.Nhs.Models.Resource.AzureMediaAsset; using LearningHub.Nhs.Models.Resource.Blocks; using LearningHub.Nhs.Models.Resource.Contribute; + using LearningHub.Nhs.Models.Resource.Files; using LearningHub.Nhs.Models.Resource.ResourceDisplay; using LearningHub.Nhs.Models.Validation; using LearningHub.Nhs.Repository; @@ -5086,7 +5087,7 @@ private List CheckQuestionBlock(BlockCollectionViewModel model) { foreach (var wsi in existingWholeSlideImages) { - if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.WholeSlideImageFile != null) + 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)) { filePath.Add(wsi.WholeSlideImage.File.FilePath); } From 99bb3d2637207544dc77e20cb03e17e3b6f20b73 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Wed, 15 May 2024 15:58:26 +0100 Subject: [PATCH 27/31] TD-3023 null check on case checkQuestionBlock --- .../Controllers/Api/ContributeController.cs | 131 +++++++++--------- .../ResourceService.cs | 131 +++++++++--------- 2 files changed, 134 insertions(+), 128 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index b5c555b08..b6d3a706a 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -794,106 +794,109 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec private List CheckQuestionBlock(BlockCollectionViewModel model) { var filePath = new List(); - foreach (var block in model.Blocks) + if (model != null && model.Blocks.Any()) { - if (block.BlockType == BlockType.Question && block.QuestionBlock != null) + foreach (var block in model.Blocks) { - if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) + if (block.BlockType == BlockType.Question && block.QuestionBlock != null) { - foreach (var answerBlock in block.QuestionBlock.Answers) + if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) { - if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null) + foreach (var answerBlock in block.QuestionBlock.Answers) { - foreach (var imageBlock in answerBlock.BlockCollection.Blocks) + if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null && answerBlock.BlockCollection.Blocks.Any()) { - if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + foreach (var imageBlock in answerBlock.BlockCollection.Blocks) { - filePath.Add(imageBlock.MediaBlock.Image.File.FilePath); + 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) + var questionBlockCollection = block.QuestionBlock.QuestionBlockCollection; + if (questionBlockCollection != null && questionBlockCollection.Blocks != null && questionBlockCollection.Blocks.Any()) { - if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) + foreach (var questionBlock in questionBlockCollection.Blocks) { - if (questionBlock.MediaBlock.Image != null) - { - filePath.Add(questionBlock.MediaBlock.Image.File.FilePath); - } - - if (questionBlock.MediaBlock.Video != null) + if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) { - if (questionBlock.MediaBlock.Video.VideoFile != null) + if (questionBlock.MediaBlock.Image != null) { - if (questionBlock.MediaBlock.Video.File != null) - { - filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); - } - - if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) - { - filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); - } + filePath.Add(questionBlock.MediaBlock.Image.File.FilePath); + } - if (questionBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + if (questionBlock.MediaBlock.Video != null) + { + if (questionBlock.MediaBlock.Video.VideoFile != null) { - filePath.Add(questionBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + if (questionBlock.MediaBlock.Video.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); + } + + 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; - if (existingWholeSlideImages != null && existingWholeSlideImages.Any()) + else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null && questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.Any()) { - foreach (var wsi in existingWholeSlideImages) + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock?.WholeSlideImageBlockItems; + if (existingWholeSlideImages != null && existingWholeSlideImages.Any()) { - 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)) + foreach (var wsi in existingWholeSlideImages) { - filePath.Add(wsi.WholeSlideImage.File.FilePath); + 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)) + { + filePath.Add(wsi.WholeSlideImage.File.FilePath); + } } } } } } - } - var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; - if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null) - { - foreach (var feedbackBlock in feedbackBlockCollection.Blocks) + var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; + if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null && feedbackBlockCollection.Blocks.Any()) { - if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) + foreach (var feedbackBlock in feedbackBlockCollection.Blocks) { - if (feedbackBlock.MediaBlock.Image != null) - { - filePath.Add(feedbackBlock.MediaBlock.Image.File.FilePath); - } - - if (feedbackBlock.MediaBlock.Video != null) + if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) { - if (feedbackBlock.MediaBlock.Video.VideoFile != null) + if (feedbackBlock.MediaBlock.Image != null) { - if (feedbackBlock.MediaBlock.Video.File != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); - } - - if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); - } + filePath.Add(feedbackBlock.MediaBlock.Image.File.FilePath); + } - if (feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + if (feedbackBlock.MediaBlock.Video != null) + { + if (feedbackBlock.MediaBlock.Video.VideoFile != null) { - filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + if (feedbackBlock.MediaBlock.Video.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); + } + + 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); + } } } } diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index 67f233123..aa83042e0 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -5026,106 +5026,109 @@ private List CheckBlockFile(BlockCollectionViewModel? publishedBlock, Bl private List CheckQuestionBlock(BlockCollectionViewModel model) { var filePath = new List(); - foreach (var block in model.Blocks) + if (model != null && model.Blocks.Any()) { - if (block.BlockType == BlockType.Question && block.QuestionBlock != null) + foreach (var block in model.Blocks) { - if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) + if (block.BlockType == BlockType.Question && block.QuestionBlock != null) { - foreach (var answerBlock in block.QuestionBlock.Answers) + if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) { - if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null) + foreach (var answerBlock in block.QuestionBlock.Answers) { - foreach (var imageBlock in answerBlock.BlockCollection.Blocks) + if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null && answerBlock.BlockCollection.Blocks.Any()) { - if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + foreach (var imageBlock in answerBlock.BlockCollection.Blocks) { - filePath.Add(imageBlock.MediaBlock.Image.File.FilePath); + 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) + var questionBlockCollection = block.QuestionBlock.QuestionBlockCollection; + if (questionBlockCollection != null && questionBlockCollection.Blocks != null && questionBlockCollection.Blocks.Any()) { - if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) + foreach (var questionBlock in questionBlockCollection.Blocks) { - if (questionBlock.MediaBlock.Image != null) - { - filePath.Add(questionBlock.MediaBlock.Image.File.FilePath); - } - - if (questionBlock.MediaBlock.Video != null) + if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) { - if (questionBlock.MediaBlock.Video.VideoFile != null) + if (questionBlock.MediaBlock.Image != null) { - if (questionBlock.MediaBlock.Video.File != null) - { - filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); - } - - if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) - { - filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); - } + filePath.Add(questionBlock.MediaBlock.Image.File.FilePath); + } - if (questionBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + if (questionBlock.MediaBlock.Video != null) + { + if (questionBlock.MediaBlock.Video.VideoFile != null) { - filePath.Add(questionBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + if (questionBlock.MediaBlock.Video.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FilePath); + } + + 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; - if (existingWholeSlideImages.Any()) + else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null && questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.Any()) { - foreach (var wsi in existingWholeSlideImages) + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems; + if (existingWholeSlideImages.Any()) { - 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)) + foreach (var wsi in existingWholeSlideImages) { - filePath.Add(wsi.WholeSlideImage.File.FilePath); + 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)) + { + filePath.Add(wsi.WholeSlideImage.File.FilePath); + } } } } } } - } - var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; - if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null) - { - foreach (var feedbackBlock in feedbackBlockCollection.Blocks) + var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; + if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null && feedbackBlockCollection.Blocks.Any()) { - if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) + foreach (var feedbackBlock in feedbackBlockCollection.Blocks) { - if (feedbackBlock.MediaBlock.Image != null) - { - filePath.Add(feedbackBlock.MediaBlock.Image.File.FilePath); - } - - if (feedbackBlock.MediaBlock.Video != null) + if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) { - if (feedbackBlock.MediaBlock.Video.VideoFile != null) + if (feedbackBlock.MediaBlock.Image != null) { - if (feedbackBlock.MediaBlock.Video.File != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); - } - - if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); - } + filePath.Add(feedbackBlock.MediaBlock.Image.File.FilePath); + } - if (feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + if (feedbackBlock.MediaBlock.Video != null) + { + if (feedbackBlock.MediaBlock.Video.VideoFile != null) { - filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + if (feedbackBlock.MediaBlock.Video.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FilePath); + } + + 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); + } } } } From f3a3ed1b3cebded9a38dbace43c9c7d27f9fe0aa Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Thu, 30 May 2024 14:04:38 +0100 Subject: [PATCH 28/31] TD-3023 Update to search entire db for case and assement blocks --- .../Controllers/Api/ContributeController.cs | 10 +- ...AssessmentContentBlockCollectionGetAll.sql | 339 ++++++++++++ ...ssessmentGuidanceBlockCollectionGetAll.sql | 339 ++++++++++++ .../Resources/CaseBlockCollectionGetAll.sql | 339 ++++++++++++ .../Resources/IBlockCollectionRepository.cs | 10 + .../Resources/BlockCollectionRepository.cs | 235 ++++++++ .../IResourceService.cs | 18 + .../ResourceService.cs | 510 ++++++++++-------- 8 files changed, 1574 insertions(+), 226 deletions(-) create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentContentBlockCollectionGetAll.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentGuidanceBlockCollectionGetAll.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/CaseBlockCollectionGetAll.sql diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index b6d3a706a..8a4ee438a 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -668,7 +668,7 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in existingAttachements) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null && x.MediaBlock.Attachment.File?.FileId == oldblock.MediaBlock.Attachment?.File?.FileId); + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null && (x.MediaBlock.Attachment.File?.FileId == oldblock.MediaBlock.Attachment?.File?.FileId || x.MediaBlock.Attachment.File?.FilePath == oldblock.MediaBlock.Attachment?.File?.FilePath)); if (entry == null) { filePaths.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); @@ -681,7 +681,7 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in existingVideos) { - 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); + 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 || x.MediaBlock.Video.VideoFile?.File?.FilePath == oldblock.MediaBlock?.Video?.VideoFile?.File?.FilePath)); if (entry == null) { if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video.File.FilePath)) @@ -707,7 +707,7 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in existingImages) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId); + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && (x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId || x.MediaBlock?.Image?.File?.FilePath == oldblock.MediaBlock?.Image?.File?.FilePath)); if (entry == null) { filePaths.Add(oldblock?.MediaBlock?.Image?.File?.FilePath); @@ -722,7 +722,7 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in imageBlock?.ImageCarouselBlock?.ImageBlockCollection?.Blocks) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks.Where(x => x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId).Any()); + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks.Where(x => x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId || x.MediaBlock?.Image?.File?.FilePath == oldblock.MediaBlock?.Image?.File?.FilePath).Any()); if (entry == null) { filePaths.Add(oldblock.MediaBlock?.Image?.File?.FilePath); @@ -738,7 +738,7 @@ 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).Any()); + 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); diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentContentBlockCollectionGetAll.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentContentBlockCollectionGetAll.sql new file mode 100644 index 000000000..5fd15075a --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentContentBlockCollectionGetAll.sql @@ -0,0 +1,339 @@ +------------------------------------------------------------------------------- +-- Author Tobi Awe +-- Created 30-05-2024 +-- Purpose Get all assessment content block collections of all undeleted resource version including published(current version only) versions while excluding the version being edited. +-- +-- Modification History +-- +-- 30-05-2024 TD-3023 Initial Revision +------------------------------------------------------------------------------- +CREATE PROCEDURE [resources].[AssessmentContentBlockCollectionGetAll] ( + @excludeResourceVersionId INT +) +AS +BEGIN + -- Table to hold BlockCollectionIds + DECLARE @BlockCollectionId TABLE (Id INT); + + -- Insert BlockCollectionIds based on the provided query + INSERT INTO @BlockCollectionId (Id) + SELECT DISTINCT [c].AssessmentContentId as [BlockCollectionId] + FROM [resources].AssessmentResourceVersion AS [c] + INNER JOIN ( + SELECT [r].[Id], [r].[ResourceId], [r].[VersionStatusId] + FROM [resources].[ResourceVersion] AS [r] + WHERE [r].[Deleted] = CAST(0 AS bit) + ) AS [t] ON [c].[ResourceVersionId] = [t].[Id] + INNER JOIN ( + SELECT [r0].[Id], [r0].[CurrentResourceVersionId] + FROM [resources].[Resource] AS [r0] + WHERE [r0].[Deleted] = CAST(0 AS bit) + ) AS [t0] ON [t].[ResourceId] = [t0].[Id] + WHERE ([c].[Deleted] = CAST(0 AS bit)) + AND ((([c].[ResourceVersionId] <> @excludeResourceVersionId) + AND ([c].[Deleted] = CAST(0 AS bit))) + AND (([t].[VersionStatusId] <> 2) + OR (([t].[VersionStatusId] = 2) + AND ([t0].[CurrentResourceVersionId] = [c].[ResourceVersionId])))) + AND [c].AssessmentContentId IS NOT NULL; + + -- Table to hold results for blocks + DECLARE @BlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Insert block data + INSERT INTO @BlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @BlockCollectionId); + + -- Select block data + SELECT br.Id, [Order], Title, BlockType, BlockCollectionId + FROM @BlockResult br + JOIN @BlockCollectionId bc ON br.BlockCollectionId = bc.Id; + + -- Select text block data + SELECT t.* + FROM resources.TextBlock t + INNER JOIN @BlockResult b ON b.Id = t.BlockId + WHERE t.Deleted = 0; + + -- WholeSlide Image Block + DECLARE @WsibResult TABLE ( + Id INT, + BlockId INT + ); + + INSERT INTO @WsibResult + SELECT w.Id, w.BlockId + FROM resources.WholeSlideImageBlock w + INNER JOIN @BlockResult b ON b.Id = w.BlockId + WHERE w.Deleted = 0; + + SELECT * FROM @WsibResult; + + -- WholeSlide Image Block Items + DECLARE @WsibiResult TABLE ( + Id INT, + WholeSlideImageBlockId INT, + WholeSlideImageId INT, + PlaceholderText NVARCHAR(255), + [Order] INT + ); + + INSERT INTO @WsibiResult + SELECT wi.Id, wi.WholeSlideImageBlockId, wi.WholeSlideImageId, wi.PlaceholderText, wi.[Order] + FROM resources.WholeSlideImageBlockItem wi + INNER JOIN @WsibResult w ON wi.WholeSlideImageBlockId = w.Id + WHERE wi.Deleted = 0; + + SELECT * FROM @WsibiResult; + + -- WholeSlide Image + DECLARE @WsiResult TABLE ( + Id INT, + Title NVARCHAR(1000), + FileId INT + ); + + INSERT INTO @WsiResult + SELECT wsi.Id, wsi.Title, wsi.FileId + FROM resources.WholeSlideImage wsi + INNER JOIN @WsibiResult wi ON wsi.Id = wi.WholeSlideImageId + WHERE wsi.Deleted = 0; + + SELECT * FROM @WsiResult; + + -- WholeSlide Image File + DECLARE @WsiFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @WsiFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @WsiResult wsi ON f.Id = wsi.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @WsiFileResult; + + -- WholeSlide Image File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @WsiFileResult wsi ON pf.FileId = wsi.Id + WHERE pf.Deleted = 0; + + -- WholeSlide Image File - Image File + SELECT wsif.* + FROM resources.WholeSlideImageFile wsif + INNER JOIN @WsiFileResult wsi ON wsif.FileId = wsi.Id + WHERE wsif.Deleted = 0; + + -- WholeSlide Image Annotation + DECLARE @WsiaResult TABLE ( + Id INT, + WholeSlideImageId INT, + ImageId INT, + [Order] INT, + Label NVARCHAR(255), + Description NVARCHAR(1000), + PinXCoordinate DECIMAL(22,19), + PinYCoordinate DECIMAL(22,19), + Colour INT + ); + + INSERT INTO @WsiaResult + SELECT ia.Id, ia.WholeSlideImageId, ia.ImageId, ia.[Order], ia.Label, ia.Description, ia.PinXCoordinate, ia.PinYCoordinate, ia.Colour + FROM resources.ImageAnnotation ia + INNER JOIN @WsiResult wsi ON ia.WholeSlideImageId = wsi.Id + WHERE ia.Deleted = 0; + + SELECT * FROM @WsiaResult; + + -- WholeSlide Image Annotation Mark + SELECT iam.* + FROM resources.ImageAnnotationMark iam + INNER JOIN @WsiaResult wsia ON iam.ImageAnnotationId = wsia.Id + WHERE iam.Deleted = 0; + + -- Media Block + DECLARE @MediaBlockResult TABLE ( + Id INT, + BlockId INT, + MediaType INT, + AttachmentId INT, + ImageId INT, + VideoId INT + ); + + INSERT INTO @MediaBlockResult + SELECT mb.Id, mb.BlockId, mb.MediaType, mb.AttachmentId, mb.ImageId, mb.VideoId + FROM resources.MediaBlock mb + INNER JOIN @BlockResult b ON mb.BlockId = b.Id + WHERE mb.Deleted = 0; + + SELECT * FROM @MediaBlockResult; + + -- Attachment + DECLARE @AttachmentResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @AttachmentResult + SELECT a.Id, a.FileId + FROM resources.Attachment a + INNER JOIN @MediaBlockResult mb ON a.Id = mb.AttachmentId + WHERE a.Deleted = 0; + + SELECT * FROM @AttachmentResult; + + -- Attachment File + DECLARE @AttachmentFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @AttachmentFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @AttachmentResult ar ON f.Id = ar.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @AttachmentFileResult; + + -- Attachment File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @AttachmentFileResult af ON pf.FileId = af.Id + WHERE pf.Deleted = 0; + + -- Image + DECLARE @ImageResult TABLE ( + Id INT, + FileId INT, + AltText NVARCHAR(125), + Description NVARCHAR(250) + ); + + INSERT INTO @ImageResult + SELECT i.Id, i.FileId, i.AltText, i.Description + FROM resources.Image i + INNER JOIN @MediaBlockResult mb ON i.Id = mb.ImageId + WHERE i.Deleted = 0; + + SELECT * FROM @ImageResult; + + -- Image File + DECLARE @ImageFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @ImageFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @ImageResult ir ON f.Id = ir.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @ImageFileResult; + + -- Image File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @ImageFileResult ifr ON pf.FileId = ifr.Id + WHERE pf.Deleted = 0; + + -- Video + DECLARE @VideoResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @VideoResult + SELECT v.Id, v.FileId + FROM resources.Video v + INNER JOIN @MediaBlockResult mb ON v.Id = mb.VideoId + WHERE v.Deleted = 0; + + SELECT * FROM @VideoResult; + + -- Video File + DECLARE @VideoFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @VideoFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @VideoResult vr ON f.Id = vr.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @VideoFileResult; + + -- Video File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @VideoFileResult vf ON pf.FileId = vf.Id + WHERE pf.Deleted = 0; + + -- Video File Detail + SELECT vf.* + FROM resources.VideoFile vf + INNER JOIN @VideoFileResult vfr ON vf.FileId = vfr.Id + WHERE vf.Deleted = 0; + + -- Question Block + DECLARE @QuestionResult TABLE ( + Id INT, + BlockId INT, + QuestionBlockCollectionId INT, + FeedbackBlockCollectionId INT, + QuestionType INT, + AllowReveal BIT + ); + + INSERT INTO @QuestionResult + SELECT qb.Id, qb.BlockId, qb.QuestionBlockCollectionId, qb.FeedbackBlockCollectionId, qb.QuestionType, qb.AllowReveal + FROM resources.QuestionBlock qb + INNER JOIN @BlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + SELECT * FROM @QuestionResult; + + -- Question Answer + SELECT qa.* + FROM resources.QuestionAnswer qa + INNER JOIN @QuestionResult qr ON qa.QuestionBlockId = qr.Id + WHERE qa.Deleted = 0; + + -- Image Carousel Block + SELECT icb.* + FROM resources.ImageCarouselBlock icb + INNER JOIN @BlockResult b ON icb.BlockId = b.Id + WHERE icb.Deleted = 0; +END +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentGuidanceBlockCollectionGetAll.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentGuidanceBlockCollectionGetAll.sql new file mode 100644 index 000000000..f8e96a7ba --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/AssessmentGuidanceBlockCollectionGetAll.sql @@ -0,0 +1,339 @@ +------------------------------------------------------------------------------- +-- Author Tobi Awe +-- Created 30-05-2024 +-- Purpose Get all assessment guidance block collections of all undeleted resource version including published(current version only) versions while excluding the version being edited. +-- +-- Modification History +-- +-- 30-05-2024 TD-3023 Initial Revision +------------------------------------------------------------------------------- +CREATE PROCEDURE [resources].[AssessmentGuidanceBlockCollectionGetAll] ( + @excludeResourceVersionId INT +) +AS +BEGIN + -- Table to hold BlockCollectionIds + DECLARE @BlockCollectionId TABLE (Id INT); + + -- Insert BlockCollectionIds based on the provided query + INSERT INTO @BlockCollectionId (Id) + SELECT DISTINCT [c].EndGuidanceId as [BlockCollectionId] + FROM [resources].AssessmentResourceVersion AS [c] + INNER JOIN ( + SELECT [r].[Id], [r].[ResourceId], [r].[VersionStatusId] + FROM [resources].[ResourceVersion] AS [r] + WHERE [r].[Deleted] = CAST(0 AS bit) + ) AS [t] ON [c].[ResourceVersionId] = [t].[Id] + INNER JOIN ( + SELECT [r0].[Id], [r0].[CurrentResourceVersionId] + FROM [resources].[Resource] AS [r0] + WHERE [r0].[Deleted] = CAST(0 AS bit) + ) AS [t0] ON [t].[ResourceId] = [t0].[Id] + WHERE ([c].[Deleted] = CAST(0 AS bit)) + AND ((([c].[ResourceVersionId] <> @excludeResourceVersionId) + AND ([c].[Deleted] = CAST(0 AS bit))) + AND (([t].[VersionStatusId] <> 2) + OR (([t].[VersionStatusId] = 2) + AND ([t0].[CurrentResourceVersionId] = [c].[ResourceVersionId])))) + AND [c].EndGuidanceId IS NOT NULL; + + -- Table to hold results for blocks + DECLARE @BlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Insert block data + INSERT INTO @BlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @BlockCollectionId); + + -- Select block data + SELECT br.Id, [Order], Title, BlockType, BlockCollectionId + FROM @BlockResult br + JOIN @BlockCollectionId bc ON br.BlockCollectionId = bc.Id; + + -- Select text block data + SELECT t.* + FROM resources.TextBlock t + INNER JOIN @BlockResult b ON b.Id = t.BlockId + WHERE t.Deleted = 0; + + -- WholeSlide Image Block + DECLARE @WsibResult TABLE ( + Id INT, + BlockId INT + ); + + INSERT INTO @WsibResult + SELECT w.Id, w.BlockId + FROM resources.WholeSlideImageBlock w + INNER JOIN @BlockResult b ON b.Id = w.BlockId + WHERE w.Deleted = 0; + + SELECT * FROM @WsibResult; + + -- WholeSlide Image Block Items + DECLARE @WsibiResult TABLE ( + Id INT, + WholeSlideImageBlockId INT, + WholeSlideImageId INT, + PlaceholderText NVARCHAR(255), + [Order] INT + ); + + INSERT INTO @WsibiResult + SELECT wi.Id, wi.WholeSlideImageBlockId, wi.WholeSlideImageId, wi.PlaceholderText, wi.[Order] + FROM resources.WholeSlideImageBlockItem wi + INNER JOIN @WsibResult w ON wi.WholeSlideImageBlockId = w.Id + WHERE wi.Deleted = 0; + + SELECT * FROM @WsibiResult; + + -- WholeSlide Image + DECLARE @WsiResult TABLE ( + Id INT, + Title NVARCHAR(1000), + FileId INT + ); + + INSERT INTO @WsiResult + SELECT wsi.Id, wsi.Title, wsi.FileId + FROM resources.WholeSlideImage wsi + INNER JOIN @WsibiResult wi ON wsi.Id = wi.WholeSlideImageId + WHERE wsi.Deleted = 0; + + SELECT * FROM @WsiResult; + + -- WholeSlide Image File + DECLARE @WsiFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @WsiFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @WsiResult wsi ON f.Id = wsi.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @WsiFileResult; + + -- WholeSlide Image File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @WsiFileResult wsi ON pf.FileId = wsi.Id + WHERE pf.Deleted = 0; + + -- WholeSlide Image File - Image File + SELECT wsif.* + FROM resources.WholeSlideImageFile wsif + INNER JOIN @WsiFileResult wsi ON wsif.FileId = wsi.Id + WHERE wsif.Deleted = 0; + + -- WholeSlide Image Annotation + DECLARE @WsiaResult TABLE ( + Id INT, + WholeSlideImageId INT, + ImageId INT, + [Order] INT, + Label NVARCHAR(255), + Description NVARCHAR(1000), + PinXCoordinate DECIMAL(22,19), + PinYCoordinate DECIMAL(22,19), + Colour INT + ); + + INSERT INTO @WsiaResult + SELECT ia.Id, ia.WholeSlideImageId, ia.ImageId, ia.[Order], ia.Label, ia.Description, ia.PinXCoordinate, ia.PinYCoordinate, ia.Colour + FROM resources.ImageAnnotation ia + INNER JOIN @WsiResult wsi ON ia.WholeSlideImageId = wsi.Id + WHERE ia.Deleted = 0; + + SELECT * FROM @WsiaResult; + + -- WholeSlide Image Annotation Mark + SELECT iam.* + FROM resources.ImageAnnotationMark iam + INNER JOIN @WsiaResult wsia ON iam.ImageAnnotationId = wsia.Id + WHERE iam.Deleted = 0; + + -- Media Block + DECLARE @MediaBlockResult TABLE ( + Id INT, + BlockId INT, + MediaType INT, + AttachmentId INT, + ImageId INT, + VideoId INT + ); + + INSERT INTO @MediaBlockResult + SELECT mb.Id, mb.BlockId, mb.MediaType, mb.AttachmentId, mb.ImageId, mb.VideoId + FROM resources.MediaBlock mb + INNER JOIN @BlockResult b ON mb.BlockId = b.Id + WHERE mb.Deleted = 0; + + SELECT * FROM @MediaBlockResult; + + -- Attachment + DECLARE @AttachmentResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @AttachmentResult + SELECT a.Id, a.FileId + FROM resources.Attachment a + INNER JOIN @MediaBlockResult mb ON a.Id = mb.AttachmentId + WHERE a.Deleted = 0; + + SELECT * FROM @AttachmentResult; + + -- Attachment File + DECLARE @AttachmentFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @AttachmentFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @AttachmentResult ar ON f.Id = ar.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @AttachmentFileResult; + + -- Attachment File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @AttachmentFileResult af ON pf.FileId = af.Id + WHERE pf.Deleted = 0; + + -- Image + DECLARE @ImageResult TABLE ( + Id INT, + FileId INT, + AltText NVARCHAR(125), + Description NVARCHAR(250) + ); + + INSERT INTO @ImageResult + SELECT i.Id, i.FileId, i.AltText, i.Description + FROM resources.Image i + INNER JOIN @MediaBlockResult mb ON i.Id = mb.ImageId + WHERE i.Deleted = 0; + + SELECT * FROM @ImageResult; + + -- Image File + DECLARE @ImageFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @ImageFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @ImageResult ir ON f.Id = ir.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @ImageFileResult; + + -- Image File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @ImageFileResult ifr ON pf.FileId = ifr.Id + WHERE pf.Deleted = 0; + + -- Video + DECLARE @VideoResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @VideoResult + SELECT v.Id, v.FileId + FROM resources.Video v + INNER JOIN @MediaBlockResult mb ON v.Id = mb.VideoId + WHERE v.Deleted = 0; + + SELECT * FROM @VideoResult; + + -- Video File + DECLARE @VideoFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @VideoFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @VideoResult vr ON f.Id = vr.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @VideoFileResult; + + -- Video File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @VideoFileResult vf ON pf.FileId = vf.Id + WHERE pf.Deleted = 0; + + -- Video File Detail + SELECT vf.* + FROM resources.VideoFile vf + INNER JOIN @VideoFileResult vfr ON vf.FileId = vfr.Id + WHERE vf.Deleted = 0; + + -- Question Block + DECLARE @QuestionResult TABLE ( + Id INT, + BlockId INT, + QuestionBlockCollectionId INT, + FeedbackBlockCollectionId INT, + QuestionType INT, + AllowReveal BIT + ); + + INSERT INTO @QuestionResult + SELECT qb.Id, qb.BlockId, qb.QuestionBlockCollectionId, qb.FeedbackBlockCollectionId, qb.QuestionType, qb.AllowReveal + FROM resources.QuestionBlock qb + INNER JOIN @BlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + SELECT * FROM @QuestionResult; + + -- Question Answer + SELECT qa.* + FROM resources.QuestionAnswer qa + INNER JOIN @QuestionResult qr ON qa.QuestionBlockId = qr.Id + WHERE qa.Deleted = 0; + + -- Image Carousel Block + SELECT icb.* + FROM resources.ImageCarouselBlock icb + INNER JOIN @BlockResult b ON icb.BlockId = b.Id + WHERE icb.Deleted = 0; +END +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/CaseBlockCollectionGetAll.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/CaseBlockCollectionGetAll.sql new file mode 100644 index 000000000..710829583 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/CaseBlockCollectionGetAll.sql @@ -0,0 +1,339 @@ +------------------------------------------------------------------------------- +-- Author Tobi Awe +-- Created 30-05-2024 +-- Purpose Get all case content block collections of all undeleted resource version including published(current version only) versions while excluding the version being edited. +-- +-- Modification History +-- +-- 30-05-2024 TD-3023 Initial Revision +------------------------------------------------------------------------------- +CREATE PROCEDURE [resources].[CaseBlockCollectionGetAll] ( + @excludeResourceVersionId INT +) +AS +BEGIN + -- Table to hold BlockCollectionIds + DECLARE @BlockCollectionId TABLE (Id INT); + + -- Insert BlockCollectionIds based on the provided query + INSERT INTO @BlockCollectionId (Id) + SELECT DISTINCT [c].[BlockCollectionId] + FROM [resources].[CaseResourceVersion] AS [c] + INNER JOIN ( + SELECT [r].[Id], [r].[ResourceId], [r].[VersionStatusId] + FROM [resources].[ResourceVersion] AS [r] + WHERE [r].[Deleted] = CAST(0 AS bit) + ) AS [t] ON [c].[ResourceVersionId] = [t].[Id] + INNER JOIN ( + SELECT [r0].[Id], [r0].[CurrentResourceVersionId] + FROM [resources].[Resource] AS [r0] + WHERE [r0].[Deleted] = CAST(0 AS bit) + ) AS [t0] ON [t].[ResourceId] = [t0].[Id] + WHERE ([c].[Deleted] = CAST(0 AS bit)) + AND ((([c].[ResourceVersionId] <> @excludeResourceVersionId) + AND ([c].[Deleted] = CAST(0 AS bit))) + AND (([t].[VersionStatusId] <> 2) + OR (([t].[VersionStatusId] = 2) + AND ([t0].[CurrentResourceVersionId] = [c].[ResourceVersionId])))) + AND [c].[BlockCollectionId] IS NOT NULL; + + -- Table to hold results for blocks + DECLARE @BlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Insert block data + INSERT INTO @BlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @BlockCollectionId); + + -- Select block data + SELECT br.Id, [Order], Title, BlockType, BlockCollectionId + FROM @BlockResult br + JOIN @BlockCollectionId bc ON br.BlockCollectionId = bc.Id; + + -- Select text block data + SELECT t.* + FROM resources.TextBlock t + INNER JOIN @BlockResult b ON b.Id = t.BlockId + WHERE t.Deleted = 0; + + -- WholeSlide Image Block + DECLARE @WsibResult TABLE ( + Id INT, + BlockId INT + ); + + INSERT INTO @WsibResult + SELECT w.Id, w.BlockId + FROM resources.WholeSlideImageBlock w + INNER JOIN @BlockResult b ON b.Id = w.BlockId + WHERE w.Deleted = 0; + + SELECT * FROM @WsibResult; + + -- WholeSlide Image Block Items + DECLARE @WsibiResult TABLE ( + Id INT, + WholeSlideImageBlockId INT, + WholeSlideImageId INT, + PlaceholderText NVARCHAR(255), + [Order] INT + ); + + INSERT INTO @WsibiResult + SELECT wi.Id, wi.WholeSlideImageBlockId, wi.WholeSlideImageId, wi.PlaceholderText, wi.[Order] + FROM resources.WholeSlideImageBlockItem wi + INNER JOIN @WsibResult w ON wi.WholeSlideImageBlockId = w.Id + WHERE wi.Deleted = 0; + + SELECT * FROM @WsibiResult; + + -- WholeSlide Image + DECLARE @WsiResult TABLE ( + Id INT, + Title NVARCHAR(1000), + FileId INT + ); + + INSERT INTO @WsiResult + SELECT wsi.Id, wsi.Title, wsi.FileId + FROM resources.WholeSlideImage wsi + INNER JOIN @WsibiResult wi ON wsi.Id = wi.WholeSlideImageId + WHERE wsi.Deleted = 0; + + SELECT * FROM @WsiResult; + + -- WholeSlide Image File + DECLARE @WsiFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @WsiFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @WsiResult wsi ON f.Id = wsi.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @WsiFileResult; + + -- WholeSlide Image File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @WsiFileResult wsi ON pf.FileId = wsi.Id + WHERE pf.Deleted = 0; + + -- WholeSlide Image File - Image File + SELECT wsif.* + FROM resources.WholeSlideImageFile wsif + INNER JOIN @WsiFileResult wsi ON wsif.FileId = wsi.Id + WHERE wsif.Deleted = 0; + + -- WholeSlide Image Annotation + DECLARE @WsiaResult TABLE ( + Id INT, + WholeSlideImageId INT, + ImageId INT, + [Order] INT, + Label NVARCHAR(255), + Description NVARCHAR(1000), + PinXCoordinate DECIMAL(22,19), + PinYCoordinate DECIMAL(22,19), + Colour INT + ); + + INSERT INTO @WsiaResult + SELECT ia.Id, ia.WholeSlideImageId, ia.ImageId, ia.[Order], ia.Label, ia.Description, ia.PinXCoordinate, ia.PinYCoordinate, ia.Colour + FROM resources.ImageAnnotation ia + INNER JOIN @WsiResult wsi ON ia.WholeSlideImageId = wsi.Id + WHERE ia.Deleted = 0; + + SELECT * FROM @WsiaResult; + + -- WholeSlide Image Annotation Mark + SELECT iam.* + FROM resources.ImageAnnotationMark iam + INNER JOIN @WsiaResult wsia ON iam.ImageAnnotationId = wsia.Id + WHERE iam.Deleted = 0; + + -- Media Block + DECLARE @MediaBlockResult TABLE ( + Id INT, + BlockId INT, + MediaType INT, + AttachmentId INT, + ImageId INT, + VideoId INT + ); + + INSERT INTO @MediaBlockResult + SELECT mb.Id, mb.BlockId, mb.MediaType, mb.AttachmentId, mb.ImageId, mb.VideoId + FROM resources.MediaBlock mb + INNER JOIN @BlockResult b ON mb.BlockId = b.Id + WHERE mb.Deleted = 0; + + SELECT * FROM @MediaBlockResult; + + -- Attachment + DECLARE @AttachmentResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @AttachmentResult + SELECT a.Id, a.FileId + FROM resources.Attachment a + INNER JOIN @MediaBlockResult mb ON a.Id = mb.AttachmentId + WHERE a.Deleted = 0; + + SELECT * FROM @AttachmentResult; + + -- Attachment File + DECLARE @AttachmentFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @AttachmentFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @AttachmentResult ar ON f.Id = ar.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @AttachmentFileResult; + + -- Attachment File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @AttachmentFileResult af ON pf.FileId = af.Id + WHERE pf.Deleted = 0; + + -- Image + DECLARE @ImageResult TABLE ( + Id INT, + FileId INT, + AltText NVARCHAR(125), + Description NVARCHAR(250) + ); + + INSERT INTO @ImageResult + SELECT i.Id, i.FileId, i.AltText, i.Description + FROM resources.Image i + INNER JOIN @MediaBlockResult mb ON i.Id = mb.ImageId + WHERE i.Deleted = 0; + + SELECT * FROM @ImageResult; + + -- Image File + DECLARE @ImageFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @ImageFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @ImageResult ir ON f.Id = ir.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @ImageFileResult; + + -- Image File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @ImageFileResult ifr ON pf.FileId = ifr.Id + WHERE pf.Deleted = 0; + + -- Video + DECLARE @VideoResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @VideoResult + SELECT v.Id, v.FileId + FROM resources.Video v + INNER JOIN @MediaBlockResult mb ON v.Id = mb.VideoId + WHERE v.Deleted = 0; + + SELECT * FROM @VideoResult; + + -- Video File + DECLARE @VideoFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @VideoFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @VideoResult vr ON f.Id = vr.FileId + WHERE f.Deleted = 0; + + SELECT * FROM @VideoFileResult; + + -- Video File - Partial File + SELECT pf.* + FROM resources.PartialFile pf + INNER JOIN @VideoFileResult vf ON pf.FileId = vf.Id + WHERE pf.Deleted = 0; + + -- Video File Detail + SELECT vf.* + FROM resources.VideoFile vf + INNER JOIN @VideoFileResult vfr ON vf.FileId = vfr.Id + WHERE vf.Deleted = 0; + + -- Question Block + DECLARE @QuestionResult TABLE ( + Id INT, + BlockId INT, + QuestionBlockCollectionId INT, + FeedbackBlockCollectionId INT, + QuestionType INT, + AllowReveal BIT + ); + + INSERT INTO @QuestionResult + SELECT qb.Id, qb.BlockId, qb.QuestionBlockCollectionId, qb.FeedbackBlockCollectionId, qb.QuestionType, qb.AllowReveal + FROM resources.QuestionBlock qb + INNER JOIN @BlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + SELECT * FROM @QuestionResult; + + -- Question Answer + SELECT qa.* + FROM resources.QuestionAnswer qa + INNER JOIN @QuestionResult qr ON qa.QuestionBlockId = qr.Id + WHERE qa.Deleted = 0; + + -- Image Carousel Block + SELECT icb.* + FROM resources.ImageCarouselBlock icb + INNER JOIN @BlockResult b ON icb.BlockId = b.Id + WHERE icb.Deleted = 0; +END +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs index 0a1a52618..e24e35540 100644 --- a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs @@ -1,8 +1,10 @@ namespace LearningHub.Nhs.Repository.Interface.Resources { + using System; using System.Collections.Generic; using System.Threading.Tasks; using LearningHub.Nhs.Models.Entities.Resource.Blocks; + using LearningHub.Nhs.Models.Enums; /// /// The BlockRepository interface. @@ -30,5 +32,13 @@ public interface IBlockCollectionRepository : IGenericRepositoryThe Block Collection Id. /// The . Task> GetQuestionBlocks(int blockCollectionId); + + /// + /// Gets the Case, AssessmentContent, AssessmentGuidance Block Collections (including child Blocks, TextBlocks, WholeSlideImageBlocks and Files) except that of the provided resource version. + /// + /// The excluded ResourceVersion Id. + /// The resource type. + /// The . + Task> GetAllBlockCollections(int excludeResourceVersionId, ResourceTypeEnum resourceTypeEnum); } } diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs index be2bc4f98..0f027f426 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs @@ -166,6 +166,37 @@ await Task.WhenAll(blockCollection.Blocks return blockCollection; } + /// + /// Gets the Case, AssessmentContent, AssessmentGuidance Block Collections (including child Blocks, TextBlocks, WholeSlideImageBlocks and Files) except that of the provided resource version. + /// + /// The excluded ResourceVersion Id. + /// The resource type. + /// The . + public async Task> GetAllBlockCollections(int excludeResourceVersionId, ResourceTypeEnum resourceTypeEnum) + { + if (resourceTypeEnum == ResourceTypeEnum.Case) + { + var caseContent = await this.GetAllCaseBlockCollections(excludeResourceVersionId); + return new Tuple(caseContent, null, null); + } + else if (resourceTypeEnum == ResourceTypeEnum.Assessment) + { + var assessmentContentTask = this.GetAllAssessmentContentBlockCollections(excludeResourceVersionId); + var assessmentGuidanceTask = this.GetAllAssessmentGuidanceBlockCollections(excludeResourceVersionId); + + await Task.WhenAll(assessmentContentTask, assessmentGuidanceTask); + + return new Tuple( + null, + await assessmentContentTask, + await assessmentGuidanceTask); + } + else + { + return new Tuple(null, null, null); + } + } + /// /// Gets the Question blocks for a particular blockCollectionId. /// @@ -416,5 +447,209 @@ private void SetAuditFieldsOnChildren(int userId, ImageCarouselBlock imageCarous this.SetAuditFieldsForCreateOrDelete(userId, imageCarouselBlock.ImageBlockCollection, isCreate); this.SetAuditFieldsOnChildren(userId, imageCarouselBlock.ImageBlockCollection, isCreate); } + + private async Task GetAllCaseBlockCollections(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