public static void MapTo(this ISchoolAddress source, ISchoolAddress target, Action <ISchoolAddress, ISchoolAddress> onMapped) { var sourceSynchSupport = source as ISchoolAddressSynchronizationSourceSupport; var targetSynchSupport = target as ISchoolAddressSynchronizationSourceSupport; // Copy contextual primary key values // Copy non-PK properties if (sourceSynchSupport.IsCitySupported) { target.City = source.City; } else { targetSynchSupport.IsCitySupported = false; } // Copy Aggregate Reference Data // ---------------------------------- // Map One-to-one relationships // ---------------------------------- // Map lists var eTagProvider = new ETagProvider(); // Convert value to ETag, if appropriate var entityWithETag = target as IHasETag; if (entityWithETag != null) { entityWithETag.ETag = eTagProvider.GetETag(source); } // Convert value to LastModifiedDate, if appropriate var dateVersionedEntity = target as IDateVersionedEntity; var etagSource = source as IHasETag; if (dateVersionedEntity != null && etagSource != null) { dateVersionedEntity.LastModifiedDate = eTagProvider.GetDateTime(etagSource.ETag); } }
public static bool SynchronizeTo(this ISchoolAddress source, ISchoolAddress target) { bool isModified = false; var sourceSupport = source as ISchoolAddressSynchronizationSourceSupport; // Back synch non-reference portion of PK (PK properties cannot be changed, therefore they can be omitted in the resource payload, but we need them for proper comparisons for persistence) // Copy non-PK properties if ((sourceSupport == null || sourceSupport.IsCitySupported) && target.City != source.City) { target.City = source.City; isModified = true; } // Sync lists return(isModified); }