public void UpdateEventEditionFromStagingDb(EditionEntity existingEdition, DWStaging.Edition stagingEdition, DateTime eventStartDate, DateTime eventEndDate) { using (var scope = new TransactionScope()) { var existingEvent = existingEdition.Event; var eventFromStaging = EditionServiceHelper.PreUpdateExistingEvent((EventEntity)existingEvent.Clone(), stagingEdition); // IF MASTERCODE HAS CHANGED: if (existingEvent.MasterCode != eventFromStaging.MasterCode) { // DELETE THIS WRONGLY UPDATED EDITION FROM CED _editionServices.DeleteEdition(existingEdition.EditionId); } else { var diffOnEvent = GetDiffOnEvent(existingEvent, eventFromStaging); var editionFromStaging = EditionServiceHelper.PreUpdateExistingEdition((EditionEntity)existingEdition.Clone(), stagingEdition, eventStartDate, eventEndDate); var diffOnEdition = existingEdition.Compare <EditionEntity, StagingDbComparableAttribute>(editionFromStaging); var existingEditionTranslation = existingEdition.EditionTranslations.Single(x => x.EditionId == existingEdition.EditionId && x.LanguageCode.ToLower() == LanguageHelper.GetBaseLanguageCultureName()); var editionTranslationFromStaging = EditionServiceHelper.PreUpdateExistingEditionTranslation((EditionTranslationEntity)existingEditionTranslation.Clone(), stagingEdition); var diffOnEditionTranslation = existingEditionTranslation.Compare <EditionTranslationEntity, StagingDbComparableAttribute>(editionTranslationFromStaging); if (diffOnEvent.Any()) { try { _eventServices.UpdateEvent(existingEvent.EventId, eventFromStaging, Constants.AutoIntegrationUserId, true); } catch (Exception exc) { var extraInfo = "Error on UpdateEvent() | EventId=" + existingEvent.EventId + " | StagingEditionEventBEID=" + stagingEdition.EventBEID; var log = CreateInternalLog(exc, extraInfo); ExternalLogHelper.Log(log, LoggingEventType.Error); return; } } if (diffOnEditionTranslation.Any() || diffOnEdition.Any() || diffOnEvent.Any()) { try { var startDateChanged = diffOnEdition.SingleOrDefault(x => x.Prop.ToLower().Contains("startdate")) != null; if (startDateChanged) { // UPDATE STARTDATE DIFF for CURRENT EDITION SetEditionStartDateDiff(editionFromStaging); } _editionServices.UpdateEdition(existingEdition.EditionId, editionFromStaging, Constants.AutoIntegrationUserId, true); if (startDateChanged) { // UPDATE STARTDATE DIFF for NEXT EDITION UpdateNextEditionStartDateDiff(existingEdition); } var eventTypeChanged = diffOnEdition.SingleOrDefault(x => x.Prop.ToLower().Contains("eventtype")) != null; if (eventTypeChanged) { if (!Utility.Constants.ValidEventTypesForCed.Contains(existingEdition.EventTypeCode) && Utility.Constants.ValidEventTypesForCed.Contains(editionFromStaging.EventTypeCode) && editionFromStaging.StartDate > DateTime.Now) { SendNotificationEmailForEditionCreation(editionFromStaging, editionTranslationFromStaging, GetEmailTemplateForEditionCreation(editionFromStaging)); } } StartNotificationProcessForEditionNameUpdate(existingEdition, existingEditionTranslation, diffOnEdition); StartNotificationProcessForEditionLocationUpdate(existingEdition, existingEditionTranslation, diffOnEdition); } catch (Exception exc) { var extraInfo = "Error on editionServices.UpdateEdition() | EditionId=" + existingEdition.EditionId + " | StagingEditionEventBEID=" + stagingEdition.EventBEID; var log = CreateInternalLog(exc, extraInfo); ExternalLogHelper.Log(log, LoggingEventType.Error); return; } } if (diffOnEditionTranslation.Any()) { try { _editionTranslationServices.UpdateEditionTranslation(editionTranslationFromStaging, Constants.AutoIntegrationUserId, true); } catch (Exception exc) { var extraInfo = "EditionTranslationId=" + existingEditionTranslation.EditionTranslationId + " | StagingEditionEventBEID=" + stagingEdition.EventBEID; var log = CreateInternalLog(exc, extraInfo); ExternalLogHelper.Log(log, LoggingEventType.Error); return; } } } scope.Complete(); } }