@@ -1477,7 +1477,7 @@ public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, b
14771477 {
14781478 if ( resource . AssessmentDetails is { EndGuidance : { } } && resource . AssessmentDetails . EndGuidance . Blocks != null )
14791479 {
1480- var assessmentFiles = this . CheckBlockFile ( resource . AssessmentDetails . EndGuidance ) ;
1480+ var assessmentFiles = this . CheckBlockFile ( extendedResourceVersion . AssessmentDetails . EndGuidance , resource . AssessmentDetails . EndGuidance ) ;
14811481 if ( assessmentFiles . Any ( ) )
14821482 {
14831483 retVal . AddRange ( assessmentFiles ) ;
@@ -1486,7 +1486,7 @@ public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, b
14861486
14871487 if ( resource . AssessmentDetails is { AssessmentContent : { } } && resource . AssessmentDetails . AssessmentContent . Blocks != null )
14881488 {
1489- var assessmentFiles = this . CheckBlockFile ( resource . AssessmentDetails . AssessmentContent ) ;
1489+ var assessmentFiles = this . CheckBlockFile ( extendedResourceVersion . AssessmentDetails . AssessmentContent , resource . AssessmentDetails . AssessmentContent ) ;
14901490 if ( assessmentFiles . Any ( ) )
14911491 {
14921492 retVal . AddRange ( assessmentFiles ) ;
@@ -1498,7 +1498,7 @@ public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, b
14981498 {
14991499 if ( deletedResource )
15001500 {
1501- var caseFiles = this . CheckBlockFile ( resource . CaseDetails . BlockCollection ) ;
1501+ var caseFiles = this . CheckBlockFile ( extendedResourceVersion . CaseDetails . BlockCollection , resource . CaseDetails . BlockCollection ) ;
15021502 if ( caseFiles . Any ( ) )
15031503 {
15041504 retVal . AddRange ( caseFiles ) ;
@@ -1557,7 +1557,7 @@ public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, b
15571557 {
15581558 if ( resource . AssessmentDetails is { EndGuidance : { } } && resource . AssessmentDetails . EndGuidance . Blocks != null )
15591559 {
1560- var assessmentFiles = this . CheckBlockFile ( resource . AssessmentDetails . EndGuidance ) ;
1560+ var assessmentFiles = this . CheckBlockFile ( null , resource . AssessmentDetails . EndGuidance ) ;
15611561 if ( assessmentFiles . Any ( ) )
15621562 {
15631563 retVal . AddRange ( assessmentFiles ) ;
@@ -1566,7 +1566,7 @@ public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, b
15661566
15671567 if ( resource . AssessmentDetails is { AssessmentContent : { } } && resource . AssessmentDetails . AssessmentContent . Blocks != null )
15681568 {
1569- var assessmentFiles = this . CheckBlockFile ( resource . AssessmentDetails . AssessmentContent ) ;
1569+ var assessmentFiles = this . CheckBlockFile ( null , resource . AssessmentDetails . AssessmentContent ) ;
15701570 if ( assessmentFiles . Any ( ) )
15711571 {
15721572 retVal . AddRange ( assessmentFiles ) ;
@@ -1576,7 +1576,7 @@ public async Task<List<string>> GetObsoleteResourceFile(int resourceVersionId, b
15761576 }
15771577 else if ( resource . ResourceTypeEnum == ResourceTypeEnum . Case )
15781578 {
1579- var caseFiles = this . CheckBlockFile ( resource . CaseDetails . BlockCollection ) ;
1579+ var caseFiles = this . CheckBlockFile ( null , resource . CaseDetails . BlockCollection ) ;
15801580 if ( caseFiles . Any ( ) )
15811581 {
15821582 retVal . AddRange ( caseFiles ) ;
@@ -4884,7 +4884,7 @@ private async Task<int> CreateNewResource(ResourceTypeEnum resourceType, string
48844884 return resourceVersionId ;
48854885 }
48864886
4887- private List < string > CheckBlockFile ( BlockCollectionViewModel model )
4887+ private List < string > CheckBlockFile ( BlockCollectionViewModel ? publishedBlock , BlockCollectionViewModel model )
48884888 {
48894889 var retVal = new List < string > ( ) ;
48904890 var caseBlockCollection = model ;
@@ -4898,7 +4898,11 @@ private List<string> CheckBlockFile(BlockCollectionViewModel model)
48984898 {
48994899 foreach ( var oldblock in existingAttachements )
49004900 {
4901- retVal . Add ( oldblock . MediaBlock . Attachment ? . File ? . FilePath ) ;
4901+ 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 ;
4902+ if ( publishedEntry == null )
4903+ {
4904+ retVal . Add ( oldblock . MediaBlock . Attachment ? . File ? . FilePath ) ;
4905+ }
49024906 }
49034907 }
49044908
@@ -4907,19 +4911,23 @@ private List<string> CheckBlockFile(BlockCollectionViewModel model)
49074911 {
49084912 foreach ( var oldblock in existingVideos )
49094913 {
4910- if ( ! string . IsNullOrWhiteSpace ( oldblock . MediaBlock . Video . File . FilePath ) )
4914+ 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 ;
4915+ if ( publishedEntry == null )
49114916 {
4912- retVal . Add ( oldblock . MediaBlock . Video . File . FilePath ) ;
4913- }
4917+ if ( ! string . IsNullOrWhiteSpace ( oldblock . MediaBlock . Video . File . FilePath ) )
4918+ {
4919+ retVal . Add ( oldblock . MediaBlock . Video . File . FilePath ) ;
4920+ }
49144921
4915- if ( ! string . IsNullOrWhiteSpace ( oldblock . MediaBlock . Video ? . File ? . VideoFile ? . File ? . FilePath ) )
4916- {
4917- retVal . Add ( oldblock . MediaBlock . Video . File . VideoFile . File . FilePath ) ;
4918- }
4922+ if ( ! string . IsNullOrWhiteSpace ( oldblock . MediaBlock . Video ? . File ? . VideoFile ? . File ? . FilePath ) )
4923+ {
4924+ retVal . Add ( oldblock . MediaBlock . Video . File . VideoFile . File . FilePath ) ;
4925+ }
49194926
4920- if ( oldblock . MediaBlock ? . Video ? . File ? . VideoFile ? . TranscriptFile ? . File ? . FilePath != null )
4921- {
4922- retVal . Add ( oldblock . MediaBlock . Video . File . VideoFile . TranscriptFile . File . FilePath ) ;
4927+ if ( oldblock . MediaBlock ? . Video ? . File ? . VideoFile ? . TranscriptFile ? . File ? . FilePath != null )
4928+ {
4929+ retVal . Add ( oldblock . MediaBlock . Video . File . VideoFile . TranscriptFile . File . FilePath ) ;
4930+ }
49234931 }
49244932 }
49254933 }
@@ -4929,7 +4937,11 @@ private List<string> CheckBlockFile(BlockCollectionViewModel model)
49294937 {
49304938 foreach ( var oldblock in existingImages )
49314939 {
4932- retVal . Add ( oldblock . MediaBlock ? . Image ? . File ? . FilePath ) ;
4940+ 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 ;
4941+ if ( publishedEntry == null )
4942+ {
4943+ retVal . Add ( oldblock . MediaBlock ? . Image ? . File ? . FilePath ) ;
4944+ }
49334945 }
49344946 }
49354947
@@ -4940,7 +4952,11 @@ private List<string> CheckBlockFile(BlockCollectionViewModel model)
49404952 {
49414953 foreach ( var oldblock in imageBlock . ImageCarouselBlock . ImageBlockCollection . Blocks )
49424954 {
4943- retVal . Add ( oldblock . MediaBlock ? . Image ? . File ? . FilePath ) ;
4955+ 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 ;
4956+ if ( publishedEntry == null )
4957+ {
4958+ retVal . Add ( oldblock . MediaBlock ? . Image ? . File ? . FilePath ) ;
4959+ }
49444960 }
49454961 }
49464962 }
@@ -4952,17 +4968,33 @@ private List<string> CheckBlockFile(BlockCollectionViewModel model)
49524968 {
49534969 foreach ( var oldblock in wsi ? . WholeSlideImageBlock ? . WholeSlideImageBlockItems )
49544970 {
4955- retVal . Add ( oldblock . WholeSlideImage ? . File ? . FilePath ) ;
4971+ 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 ;
4972+ if ( publishedEntry == null )
4973+ {
4974+ retVal . Add ( oldblock . WholeSlideImage ? . File ? . FilePath ) ;
4975+ }
49564976 }
49574977 }
49584978 }
49594979 }
49604980
49614981 var questionFiles = this . CheckQuestionBlock ( caseBlockCollection ) ;
4962- if ( questionFiles . Any ( ) )
4982+ var publishedQuestionFiles = ( publishedBlock != null && publishedBlock . Blocks . Any ( ) ) ? this . CheckQuestionBlock ( publishedBlock ) : new List < string > ( ) ;
4983+ if ( questionFiles . Any ( ) && ! publishedQuestionFiles . Any ( ) )
49634984 {
49644985 retVal . AddRange ( questionFiles ) ;
49654986 }
4987+ else if ( questionFiles . Any ( ) && publishedQuestionFiles . Any ( ) )
4988+ {
4989+ foreach ( var file in questionFiles )
4990+ {
4991+ var publishedEntry = publishedQuestionFiles . FirstOrDefault ( x => x . Equals ( file ) ) ;
4992+ if ( publishedEntry == null )
4993+ {
4994+ retVal . Add ( file ) ;
4995+ }
4996+ }
4997+ }
49664998 }
49674999
49685000 return retVal ;
@@ -5027,12 +5059,15 @@ private List<string> CheckQuestionBlock(BlockCollectionViewModel model)
50275059 }
50285060 else if ( questionBlock . BlockType == BlockType . WholeSlideImage && questionBlock . WholeSlideImageBlock != null )
50295061 {
5030- var existingWholeSlideImages = questionBlock . WholeSlideImageBlock . WholeSlideImageBlockItems . ToList ( ) ;
5062+ var existingWholeSlideImages = questionBlock . WholeSlideImageBlock . WholeSlideImageBlockItems ;
50315063 if ( existingWholeSlideImages . Any ( ) )
50325064 {
50335065 foreach ( var wsi in existingWholeSlideImages )
50345066 {
5035- filePath . Add ( wsi . WholeSlideImage ? . File ? . FilePath ) ;
5067+ if ( wsi . WholeSlideImage != null && wsi . WholeSlideImage . File != null )
5068+ {
5069+ filePath . Add ( wsi . WholeSlideImage . File . FilePath ) ;
5070+ }
50365071 }
50375072 }
50385073 }
0 commit comments