@@ -350,8 +350,8 @@ private static async Task<Site> CreateSiteAsync(
350350 SiteIdentifierType ? siteIdentifierType ,
351351 CancellationToken cancellationToken )
352352 {
353- var address = await LocationMapper . AddressToGold ( representative . Location ? . Address , getCountryById , cancellationToken ) ;
354- var communication = LocationMapper . CommunicationToGold ( representative . Communication ) ;
353+ var ( address , communication ) = await ResolveLocationPartsAsync ( representative , getCountryById , cancellationToken ) ;
354+ var isPermanentLandHolding = representative . CphRelationshipType . IsPermanentLandHolding ( ) ;
355355
356356 var location = Location . Create (
357357 representative . Location ? . OsMapReference ,
@@ -371,11 +371,11 @@ private static async Task<Site> CreateSiteAsync(
371371 SourceSystemType . SAM . ToString ( ) ,
372372 null ,
373373 representative . Deleted ,
374- representative . CphRelationshipType . IsPermanentLandHolding ( ) ? null : representative . SecondaryCph ,
374+ isPermanentLandHolding ? null : representative . SecondaryCph ,
375375 representative . CphTypeIdentifier ,
376376 siteType ,
377377 location ,
378- representative . CphRelationshipType . IsPermanentLandHolding ( ) ? representative . SecondaryCph : null ) ;
378+ isPermanentLandHolding ? representative . SecondaryCph : null ) ;
379379
380380 ApplySiteData ( site , goldSiteId , representative , goldSiteGroupMarks , goldParties , species , activities , siteIdentifierType ) ;
381381
@@ -394,6 +394,7 @@ private static async Task<Site> UpdateSiteAsync(
394394 SiteIdentifierType ? siteIdentifierType ,
395395 CancellationToken cancellationToken )
396396 {
397+ var isPermanentLandHolding = representative . CphRelationshipType . IsPermanentLandHolding ( ) ;
397398 var site = existing . ToDomain ( ) ;
398399
399400 site . Update (
@@ -405,12 +406,11 @@ private static async Task<Site> UpdateSiteAsync(
405406 SourceSystemType . SAM . ToString ( ) ,
406407 null ,
407408 representative . Deleted ,
408- representative . CphRelationshipType . IsPermanentLandHolding ( ) ? null : representative . SecondaryCph ,
409+ isPermanentLandHolding ? null : representative . SecondaryCph ,
409410 representative . CphTypeIdentifier ,
410- representative . CphRelationshipType . IsPermanentLandHolding ( ) ? representative . SecondaryCph : null ) ;
411+ isPermanentLandHolding ? representative . SecondaryCph : null ) ;
411412
412- var updatedAddress = await LocationMapper . AddressToGold ( representative . Location ? . Address , getCountryById , cancellationToken ) ;
413- var updatedCommunication = LocationMapper . CommunicationToGold ( representative . Communication ) ;
413+ var ( updatedAddress , updatedCommunication ) = await ResolveLocationPartsAsync ( representative , getCountryById , cancellationToken ) ;
414414
415415 // Always set the derived site type (may be null if no mapping found).
416416 site . SetSiteType ( siteType , representative . LastUpdatedDate ) ;
@@ -429,6 +429,16 @@ private static async Task<Site> UpdateSiteAsync(
429429 }
430430
431431
432+ private static async Task < ( Address address , Communication communication ) > ResolveLocationPartsAsync (
433+ SamHoldingDocument representative ,
434+ Func < string ? , CancellationToken , Task < CountryDocument ? > > getCountryById ,
435+ CancellationToken cancellationToken )
436+ {
437+ var address = await LocationMapper . AddressToGold ( representative . Location ? . Address , getCountryById , cancellationToken ) ;
438+ var communication = LocationMapper . CommunicationToGold ( representative . Communication ) ;
439+ return ( address , communication ) ;
440+ }
441+
432442 private static async Task < List < ( string searchValue , string ? typeId , string ? typeName ) > > GetDistinctReferenceDataAsync (
433443 IEnumerable < string ? > rawCodes ,
434444 Func < string ? , CancellationToken , Task < ( string ? typeId , string ? typeName ) > > findAsync ,
0 commit comments