Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,13 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec
{
foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems)
{
var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any());
if (entry == null)
if (oldblock != null && (oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingComplete || oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingFailed))
{
filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath);
var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any());
if (entry == null)
{
filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath);
}
}
}
}
Expand Down Expand Up @@ -809,7 +812,7 @@ private Dictionary<int, string> CheckQuestionBlock(BlockCollectionViewModel mode
{
foreach (var imageBlock in answerBlock.BlockCollection.Blocks)
{
if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null)
if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null && imageBlock.MediaBlock.Image.File != null)
{
filePath.Add(imageBlock.MediaBlock.Image.File.FileId, imageBlock.MediaBlock.Image.File.FilePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-- Modification History
--
-- 31-05-2024 TD-3023 Initial Revision
-- 04-06-2024 TD-3023 Included answer blocks to the search
-------------------------------------------------------------------------------


Expand Down Expand Up @@ -93,6 +94,14 @@ END
BlockCollectionId INT
);

DECLARE @QABlock TABLE (
Id INT,
[Order] INT,
Title NVARCHAR(200),
BlockType INT,
BlockCollectionId INT
);

-- Table to hold results for blocks
DECLARE @BlockResult TABLE (
Id INT,
Expand Down Expand Up @@ -129,6 +138,20 @@ END
INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id
WHERE qb.Deleted = 0;

-- Insert answer question block data
INSERT INTO @QABlock
SELECT qb.Id, [Order], Title, BlockType, BlockCollectionId
FROM resources.QuestionBlock qb
INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id
WHERE qb.Deleted = 0;

--Insert AnswerBlockcollectionId
INSERT INTO @BlockCollectionId (Id)
SELECT qa.BlockCollectionId
FROM resources.QuestionAnswer qa
INNER JOIN @QABlock b ON qa.QuestionBlockId = b.Id
WHERE qa.Deleted = 0;


-- Insert block data
INSERT INTO @BlockResult
Expand Down Expand Up @@ -344,6 +367,7 @@ END
DECLARE @_QuestionBlockCollectionId TABLE (Id INT);
DECLARE @_ImageCarouselBlockCollectionId TABLE (Id INT);
DECLARE @_AllBlockAssociatedFiles TABLE (FileId INT, FilePath NVARCHAR(200));
DECLARE @_QABlock TABLE (Id INT,[Order] INT,Title NVARCHAR(200),BlockType INT,BlockCollectionId INT);

-- Insert BlockCollectionIds based on the provided query
IF @resourceType = 10
Expand Down Expand Up @@ -443,7 +467,19 @@ END
INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id
WHERE qb.Deleted = 0;

-- Insert answer question block data
INSERT INTO @_QABlock
SELECT qb.Id, [Order], Title, BlockType, BlockCollectionId
FROM resources.QuestionBlock qb
INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id
WHERE qb.Deleted = 0;

--Insert AnswerBlockcollectionId
INSERT INTO @_BlockCollectionId (Id)
SELECT qa.BlockCollectionId
FROM resources.QuestionAnswer qa
INNER JOIN @_QABlock b ON qa.QuestionBlockId = b.Id
WHERE qa.Deleted = 0;



Expand Down Expand Up @@ -676,4 +712,4 @@ END
).value('.', 'NVARCHAR(MAX)'), 1, 2, '');

SET @filePath = @result;
END
END
Original file line number Diff line number Diff line change
Expand Up @@ -438,73 +438,5 @@ private void SetAuditFieldsOnChildren(int userId, ImageCarouselBlock imageCarous
this.SetAuditFieldsForCreateOrDelete(userId, imageCarouselBlock.ImageBlockCollection, isCreate);
this.SetAuditFieldsOnChildren(userId, imageCarouselBlock.ImageBlockCollection, isCreate);
}

private async Task<BlockCollection> GetResourceBlockCollectionsFilePath(int excludeResourceVersionId)
{
var command = new SqlCommand
{
CommandType = CommandType.StoredProcedure,
CommandText = "[resources].[CaseBlockCollectionGetAll]",
Parameters = { new SqlParameter("@excludeResourceVersionId", SqlDbType.Int) { Value = excludeResourceVersionId } },
};

var results = this.DbContext.MultipleResults(command)
.With<Block>()
.With<TextBlock>()
.With<WholeSlideImageBlock>()
.With<WholeSlideImageBlockItem>()
.With<WholeSlideImage>()
.With<File>()
.With<PartialFile>()
.With<WholeSlideImageFile>()
.With<ImageAnnotation>()
.With<ImageAnnotationMark>()
.With<MediaBlock>()
.With<Attachment>()
.With<File>()
.With<PartialFile>()
.With<Image>()
.With<File>()
.With<PartialFile>()
.With<Video>()
.With<File>()
.With<PartialFile>()
.With<VideoFile>()
.With<QuestionBlock>()
.With<QuestionAnswer>()
.With<ImageCarouselBlock>()
.Execute();

var blocks = results[0].OfType<Block>().ToArray();
var textBlocks = results[1].OfType<TextBlock>();
var wholeSlideImgBlocks = GetWholeSlideImageBlocks(results);
var mediaBlocks = GetMediaBlocks(results);
var questionBlocks = GetQuestionBlocks(results);
var imgCarouselBlocks = results[23].OfType<ImageCarouselBlock>();

foreach (var block in blocks)
{
block.TextBlock = textBlocks.FirstOrDefault(t => t.BlockId == block.Id);
block.WholeSlideImageBlock = wholeSlideImgBlocks.FirstOrDefault(w => w.BlockId == block.Id);
block.MediaBlock = mediaBlocks.FirstOrDefault(m => m.BlockId == block.Id);
block.QuestionBlock = questionBlocks.FirstOrDefault(q => q.BlockId == block.Id);
block.ImageCarouselBlock = imgCarouselBlocks.FirstOrDefault(i => i.BlockId == block.Id);
}

var blockCollection = new BlockCollection
{
Blocks = blocks,
};

await Task.WhenAll(blockCollection.Blocks
.Where(block => block.QuestionBlock != null)
.Select(block => this.FillInPartialQuestionBlock(block.QuestionBlock)));

await Task.WhenAll(blockCollection.Blocks
.Where(block => block.ImageCarouselBlock != null)
.Select(block => this.FillInPartialImageCarouselBlock(block.ImageCarouselBlock)));

return blockCollection;
}
}
}
11 changes: 7 additions & 4 deletions WebAPI/LearningHub.Nhs.Services/ResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5033,10 +5033,13 @@ private List<string> CheckBlockFile(BlockCollectionViewModel? publishedBlock, Bl
{
foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems)
{
var publishedEntry = (publishedBlock != null && publishedBlock.Blocks.Any()) ? publishedBlock.Blocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath || x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId).Any()) : null;
if (publishedEntry == null)
if (oldblock != null && (oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingComplete || oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingFailed))
{
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?.FilePath == oldblock.WholeSlideImage?.File?.FilePath || x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId).Any()) : null;
if (publishedEntry == null)
{
retVal.Add(oldblock.WholeSlideImage?.File?.FilePath);
}
}
}
}
Expand Down Expand Up @@ -5083,7 +5086,7 @@ private Dictionary<int, string> CheckQuestionBlock(BlockCollectionViewModel mode
{
foreach (var imageBlock in answerBlock.BlockCollection.Blocks)
{
if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null)
if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null && imageBlock.MediaBlock.Image.File != null)
{
filePath.Add(imageBlock.MediaBlock.Image.File.FileId, imageBlock.MediaBlock.Image.File.FilePath);
}
Expand Down