/// <summary> /// Posts the save changes. /// </summary> /// <param name="dbContext">The database context.</param> public override void PostSaveChanges( Data.DbContext dbContext ) { if ( HistoryChanges != null && HistoryChanges.Any() && HistoryPersonId.HasValue ) { HistoryService.SaveChanges( (RockContext)dbContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), HistoryPersonId.Value, HistoryChanges, true, this.ModifiedByPersonAliasId ); } base.PostSaveChanges( dbContext ); }
/// <summary> /// Called after the save operation has been executed /// </summary> /// <remarks> /// This method is only called if <see cref="M:Rock.Data.EntitySaveHook`1.PreSave" /> returns /// without error. /// </remarks> protected override void PostSave() { var rockContext = ( RockContext )this.RockContext; if (HistoryChanges?.Any() == true && HistoryPersonId.HasValue) { HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), HistoryPersonId.Value, HistoryChanges, true, Entity.ModifiedByPersonAliasId); } base.PostSave(); }
/// <summary> /// Posts the save changes. /// </summary> /// <param name="dbContext">The database context.</param> public override void PostSaveChanges(Data.DbContext dbContext) { int?historyEntityId = (HistoryEntityId.HasValue && HistoryEntityId.Value > 0) ? HistoryEntityId.Value : this.EntityId; var rockContext = dbContext as RockContext; if (HistoryChanges != null && HistoryChanges.Any() && HistoryEntityTypeId.HasValue && historyEntityId.HasValue) { if (HistoryEntityTypeId.Value == EntityTypeCache.Get(typeof(Person)).Id) { HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), historyEntityId.Value, HistoryChanges, string.Empty, typeof(Attribute), AttributeId, true, this.ModifiedByPersonAliasId, dbContext.SourceOfChange); } else { HistoryService.SaveChanges(rockContext, typeof(Group), Rock.SystemGuid.Category.HISTORY_GROUP_CHANGES.AsGuid(), historyEntityId.Value, HistoryChanges, string.Empty, typeof(Attribute), AttributeId, true, this.ModifiedByPersonAliasId, dbContext.SourceOfChange); } } if (this.PostSaveAttributeValueHistoryCurrent) { var attributeValueHistoricalService = new AttributeValueHistoricalService(rockContext); var attributeValueHistoricalPreviousCurrentRow = attributeValueHistoricalService.Queryable().Where(a => a.AttributeValueId == this.Id && a.CurrentRowIndicator == true).FirstOrDefault(); var saveChangesDateTime = RockDateTime.Now; if (attributeValueHistoricalPreviousCurrentRow != null) { attributeValueHistoricalPreviousCurrentRow.CurrentRowIndicator = false; attributeValueHistoricalPreviousCurrentRow.ExpireDateTime = saveChangesDateTime; } var attributeValueHistoricalCurrent = AttributeValueHistorical.CreateCurrentRowFromAttributeValue(this, saveChangesDateTime); attributeValueHistoricalService.Add(attributeValueHistoricalCurrent); rockContext.SaveChanges(); } // If this a Person Attribute, Update the ModifiedDateTime on the Person that this AttributeValue is associated with if (this.EntityId.HasValue && AttributeCache.Get(this.AttributeId)?.EntityTypeId == EntityTypeCache.Get <Rock.Model.Person>().Id) { var currentDateTime = RockDateTime.Now; int personId = this.EntityId.Value; var qryPersonsToUpdate = new PersonService(rockContext).Queryable(true, true).Where(a => a.Id == personId); rockContext.BulkUpdate(qryPersonsToUpdate, p => new Person { ModifiedDateTime = currentDateTime, ModifiedByPersonAliasId = this.ModifiedByPersonAliasId }); } base.PostSaveChanges(dbContext); }
/// <summary> /// Method that will be called on an entity immediately after the item is saved /// </summary> /// <param name="dbContext">The database context.</param> public override void PostSaveChanges(DbContext dbContext) { if (HistoryChanges.Any()) { HistoryService.SaveChanges((RockContext)dbContext, typeof(FinancialTransaction), Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(), this.Id, HistoryChanges, true, this.ModifiedByPersonAliasId); } foreach (var keyVal in BatchHistoryChanges) { if (keyVal.Value.Any()) { HistoryService.SaveChanges((RockContext)dbContext, typeof(FinancialBatch), Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(), keyVal.Key, keyVal.Value, string.Empty, typeof(FinancialTransaction), this.Id, true, this.ModifiedByPersonAliasId); } } base.PostSaveChanges(dbContext); }
/// <summary> /// Posts the save changes. /// </summary> /// <param name="dbContext">The database context.</param> public override void PostSaveChanges(Data.DbContext dbContext) { int?historyEntityId = (HistoryEntityId.HasValue && HistoryEntityId.Value > 0) ? HistoryEntityId.Value : this.EntityId; if (HistoryChanges != null && HistoryChanges.Any() && HistoryEntityTypeId.HasValue && historyEntityId.HasValue) { if (HistoryEntityTypeId.Value == EntityTypeCache.Read(typeof(Person)).Id) { HistoryService.SaveChanges((RockContext)dbContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), historyEntityId.Value, HistoryChanges, string.Empty, typeof(Attribute), AttributeId, true, this.ModifiedByPersonAliasId); } else { HistoryService.SaveChanges((RockContext)dbContext, typeof(Group), Rock.SystemGuid.Category.HISTORY_GROUP_CHANGES.AsGuid(), historyEntityId.Value, HistoryChanges, string.Empty, typeof(Attribute), AttributeId, true, this.ModifiedByPersonAliasId); } } base.PostSaveChanges(dbContext); }
/// <summary> /// Method that will be called on an entity immediately after the item is saved. /// </summary> /// <param name="dbContext">The database context.</param> public override void PostSaveChanges(Data.DbContext dbContext) { var rockContext = ( RockContext )dbContext; // It is possible that we have a UserLogin without a PersonId, in these cases we don't want to save a person history record. if (HistoryChanges != null && HistoryChanges.Any() && this.PersonId.HasValue) { try { HistoryService.SaveChanges(( RockContext )dbContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_ACTIVITY.AsGuid(), this.PersonId.Value, HistoryChanges, this.UserName, typeof(UserLogin), this.Id, true, this.ModifiedByPersonAliasId, null); } catch (Exception ex) { // Just log the problem and move on... ExceptionLogService.LogException(ex); } } base.PostSaveChanges(dbContext); }