コード例 #1
0
        /// <summary>
        /// Pres the save.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, System.Data.Entity.Infrastructure.DbEntityEntry entry)
        {
            var rockContext = (RockContext)dbContext;

            HistoryChangeList      = new History.HistoryChangeList();
            BatchHistoryChangeList = new Dictionary <int, History.HistoryChangeList> ();

            switch (entry.State)
            {
            case System.Data.Entity.EntityState.Added:
            {
                HistoryChangeList.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "Transaction");

                string person = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);

                History.EvaluateChange(HistoryChangeList, "Authorized Person", string.Empty, person);
                History.EvaluateChange(HistoryChangeList, "Batch", string.Empty, History.GetValue <FinancialBatch>(Batch, BatchId, rockContext));
                History.EvaluateChange(HistoryChangeList, "Gateway", string.Empty, History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                History.EvaluateChange(HistoryChangeList, "Transaction Date/Time", (DateTime?)null, TransactionDateTime);
                History.EvaluateChange(HistoryChangeList, "Transaction Code", string.Empty, TransactionCode);
                History.EvaluateChange(HistoryChangeList, "Summary", string.Empty, Summary);
                History.EvaluateChange(HistoryChangeList, "Type", (int?)null, TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Source", (int?)null, SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Scheduled Transaction Id", (int?)null, ScheduledTransactionId);
                History.EvaluateChange(HistoryChangeList, "Processed By", string.Empty, History.GetValue <PersonAlias>(ProcessedByPersonAlias, ProcessedByPersonAliasId, rockContext));
                History.EvaluateChange(HistoryChangeList, "Processed Date/Time", (DateTime?)null, ProcessedDateTime);
                History.EvaluateChange(HistoryChangeList, "Status", string.Empty, Status);
                History.EvaluateChange(HistoryChangeList, "Status Message", string.Empty, StatusMessage);

                int?batchId = Batch != null ? Batch.Id : BatchId;
                if (batchId.HasValue)
                {
                    var batchChanges = new History.HistoryChangeList();
                    batchChanges.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "Transaction").SetNewValue($"{this.TotalAmount.FormatAsCurrency()} for {person}");
                    BatchHistoryChangeList.Add(batchId.Value, batchChanges);
                }

                break;
            }

            case System.Data.Entity.EntityState.Modified:
            {
                string origPerson = History.GetValue <PersonAlias>(null, entry.OriginalValues["AuthorizedPersonAliasId"].ToStringSafe().AsIntegerOrNull(), rockContext);
                string person     = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);
                History.EvaluateChange(HistoryChangeList, "Authorized Person", origPerson, person);

                int?origBatchId = entry.OriginalValues["BatchId"].ToStringSafe().AsIntegerOrNull();
                int?batchId     = Batch != null ? Batch.Id : BatchId;
                if (!batchId.Equals(origBatchId))
                {
                    string origBatch = History.GetValue <FinancialBatch>(null, origBatchId, rockContext);
                    string batch     = History.GetValue <FinancialBatch>(Batch, BatchId, rockContext);
                    History.EvaluateChange(HistoryChangeList, "Batch", origBatch, batch);
                }

                int?origGatewayId = entry.OriginalValues["FinancialGatewayId"].ToStringSafe().AsIntegerOrNull();
                if (!FinancialGatewayId.Equals(origGatewayId))
                {
                    History.EvaluateChange(HistoryChangeList, "Gateway", History.GetValue <FinancialGateway>(null, origGatewayId, rockContext), History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                }

                History.EvaluateChange(HistoryChangeList, "Transaction Date/Time", entry.OriginalValues["TransactionDateTime"].ToStringSafe().AsDateTime(), TransactionDateTime);
                History.EvaluateChange(HistoryChangeList, "Transaction Code", entry.OriginalValues["TransactionCode"].ToStringSafe(), TransactionCode);
                History.EvaluateChange(HistoryChangeList, "Summary", entry.OriginalValues["Summary"].ToStringSafe(), Summary);
                History.EvaluateChange(HistoryChangeList, "Type", entry.OriginalValues["TransactionTypeValueId"].ToStringSafe().AsIntegerOrNull(), TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Source", entry.OriginalValues["SourceTypeValueId"].ToStringSafe().AsIntegerOrNull(), SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Scheduled Transaction Id", entry.OriginalValues["ScheduledTransactionId"].ToStringSafe().AsIntegerOrNull(), ScheduledTransactionId);
                History.EvaluateChange(HistoryChangeList, "Processed By", entry.OriginalValues["ProcessedByPersonAliasId"].ToStringSafe().AsIntegerOrNull(), ProcessedByPersonAlias, ProcessedByPersonAliasId, rockContext);
                History.EvaluateChange(HistoryChangeList, "Processed Date/Time", entry.OriginalValues["ProcessedDateTime"].ToStringSafe().AsDateTime(), ProcessedDateTime);
                History.EvaluateChange(HistoryChangeList, "Status", entry.OriginalValues["Status"].ToStringSafe(), Status);
                History.EvaluateChange(HistoryChangeList, "Status Message", entry.OriginalValues["StatusMessage"].ToStringSafe(), StatusMessage);

                if (!batchId.Equals(origBatchId))
                {
                    var batchChanges = new History.HistoryChangeList();

                    if (origBatchId.HasValue)
                    {
                        batchChanges.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Transaction").SetOldValue($"{this.TotalAmount.FormatAsCurrency()} for {person}");
                    }
                    if (batchId.HasValue)
                    {
                        batchChanges.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "Transaction").SetNewValue($"{this.TotalAmount.FormatAsCurrency()} for {person}");
                    }

                    BatchHistoryChangeList.Add(batchId.Value, batchChanges);
                }
                else
                {
                    if (batchId.HasValue)
                    {
                        var batchChanges = new History.HistoryChangeList();
                        batchChanges.AddChange(History.HistoryVerb.Modify, History.HistoryChangeType.Record, $"Transaction Id:{Id}");
                        BatchHistoryChangeList.Add(batchId.Value, batchChanges);
                    }
                }
                break;
            }

            case System.Data.Entity.EntityState.Deleted:
            {
                HistoryChangeList.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Transaction");

                int?batchId = Batch != null ? Batch.Id : BatchId;
                if (batchId.HasValue)
                {
                    string batch        = History.GetValue <FinancialBatch>(Batch, BatchId, rockContext);
                    string person       = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);
                    var    batchChanges = new History.HistoryChangeList();
                    batchChanges.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Transaction").SetOldValue($"{this.TotalAmount.FormatAsCurrency()} for {person}");

                    BatchHistoryChangeList.Add(batchId.Value, batchChanges);
                }

                // since images have a cascade delete relationship, make sure the PreSaveChanges gets called
                var childImages = new FinancialTransactionImageService(dbContext as RockContext).Queryable().Where(a => a.TransactionId == this.Id);
                foreach (var image in childImages)
                {
                    image.PreSaveChanges(dbContext, entry.State);
                }
                break;
            }
            }

            base.PreSaveChanges(dbContext, entry);
        }
コード例 #2
0
        /// <summary>
        /// Pres the save.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, DbEntityEntry entry)
        {
            var rockContext = (RockContext)dbContext;

            HistoryChangeList = new History.HistoryChangeList();

            switch (entry.State)
            {
            case EntityState.Added:
            {
                HistoryChangeList.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "Transaction");

                string person = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);

                History.EvaluateChange(HistoryChangeList, "Authorized Person", string.Empty, person);
                History.EvaluateChange(HistoryChangeList, "Gateway", string.Empty, History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                History.EvaluateChange(HistoryChangeList, "Gateway Schedule Id", string.Empty, GatewayScheduleId);
                History.EvaluateChange(HistoryChangeList, "Transaction Code", string.Empty, TransactionCode);
                History.EvaluateChange(HistoryChangeList, "Summary", string.Empty, Summary);
                History.EvaluateChange(HistoryChangeList, "Type", (int?)null, TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Source", (int?)null, SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Frequency", (int?)null, TransactionFrequencyValue, TransactionFrequencyValueId);
                History.EvaluateChange(HistoryChangeList, "Start Date", (DateTime?)null, StartDate);
                History.EvaluateChange(HistoryChangeList, "End Date", (DateTime?)null, EndDate);
                History.EvaluateChange(HistoryChangeList, "Number of Payments", (int?)null, NumberOfPayments);
                History.EvaluateChange(HistoryChangeList, "Is Active", (bool?)null, IsActive);
                History.EvaluateChange(HistoryChangeList, "Card Reminder Date", (DateTime?)null, CardReminderDate);
                History.EvaluateChange(HistoryChangeList, "Last Reminded Date", (DateTime?)null, LastRemindedDate);

                break;
            }

            case EntityState.Modified:
            {
                string origPerson = History.GetValue <PersonAlias>(null, entry.OriginalValues["AuthorizedPersonAliasId"].ToStringSafe().AsIntegerOrNull(), rockContext);
                string person     = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);
                History.EvaluateChange(HistoryChangeList, "Authorized Person", origPerson, person);

                int?origGatewayId = entry.OriginalValues["FinancialGatewayId"].ToStringSafe().AsIntegerOrNull();
                if (!FinancialGatewayId.Equals(origGatewayId))
                {
                    History.EvaluateChange(HistoryChangeList, "Gateway", History.GetValue <FinancialGateway>(null, origGatewayId, rockContext), History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                }

                History.EvaluateChange(HistoryChangeList, "Gateway Schedule Id", entry.OriginalValues["GatewayScheduleId"].ToStringSafe(), GatewayScheduleId);
                History.EvaluateChange(HistoryChangeList, "Transaction Code", entry.OriginalValues["TransactionCode"].ToStringSafe(), TransactionCode);
                History.EvaluateChange(HistoryChangeList, "Summary", entry.OriginalValues["Summary"].ToStringSafe(), Summary);
                History.EvaluateChange(HistoryChangeList, "Type", entry.OriginalValues["TransactionTypeValueId"].ToStringSafe().AsIntegerOrNull(), TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Source", entry.OriginalValues["SourceTypeValueId"].ToStringSafe().AsIntegerOrNull(), SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Frequency", entry.OriginalValues["TransactionFrequencyValueId"].ToStringSafe().AsIntegerOrNull(), TransactionFrequencyValue, TransactionFrequencyValueId);
                History.EvaluateChange(HistoryChangeList, "Start Date", entry.OriginalValues["StartDate"].ToStringSafe().AsDateTime(), StartDate);
                History.EvaluateChange(HistoryChangeList, "End Date", entry.OriginalValues["EndDate"].ToStringSafe().AsDateTime(), EndDate);
                History.EvaluateChange(HistoryChangeList, "Number of Payments", entry.OriginalValues["EndDate"].ToStringSafe().AsIntegerOrNull(), NumberOfPayments);
                History.EvaluateChange(HistoryChangeList, "Is Active", entry.OriginalValues["IsActive"].ToStringSafe().AsBooleanOrNull(), IsActive);
                History.EvaluateChange(HistoryChangeList, "Card Reminder Date", entry.OriginalValues["CardReminderDate"].ToStringSafe().AsDateTime(), CardReminderDate);
                History.EvaluateChange(HistoryChangeList, "Last Reminded Date", entry.OriginalValues["LastRemindedDate"].ToStringSafe().AsDateTime(), LastRemindedDate);

                break;
            }

            case EntityState.Deleted:
            {
                HistoryChangeList.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Transaction");

                break;
            }
            }

            base.PreSaveChanges(dbContext, entry);
        }
コード例 #3
0
ファイル: FinancialTransaction.cs プロジェクト: sjison/Rock
        /// <summary>
        /// Pres the save.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry"></param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, System.Data.Entity.Infrastructure.DbEntityEntry entry)
        {
            var rockContext = (RockContext)dbContext;

            HistoryChanges      = new List <string>();
            BatchHistoryChanges = new Dictionary <int, List <string> >();

            switch (entry.State)
            {
            case System.Data.Entity.EntityState.Added:
            {
                HistoryChanges.Add("Created Transaction");

                string person = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);

                History.EvaluateChange(HistoryChanges, "Authorized Person", string.Empty, person);
                History.EvaluateChange(HistoryChanges, "Batch", string.Empty, History.GetValue <FinancialBatch>(Batch, BatchId, rockContext));
                History.EvaluateChange(HistoryChanges, "Gateway", string.Empty, History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                History.EvaluateChange(HistoryChanges, "Transaction Date/Time", (DateTime?)null, TransactionDateTime);
                History.EvaluateChange(HistoryChanges, "Transaction Code", string.Empty, TransactionCode);
                History.EvaluateChange(HistoryChanges, "Summary", string.Empty, Summary);
                History.EvaluateChange(HistoryChanges, "Type", (int?)null, TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChanges, "Source", (int?)null, SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChanges, "Scheduled Transaction Id", (int?)null, ScheduledTransactionId);
                History.EvaluateChange(HistoryChanges, "Processed By", string.Empty, History.GetValue <PersonAlias>(ProcessedByPersonAlias, ProcessedByPersonAliasId, rockContext));
                History.EvaluateChange(HistoryChanges, "Processed Date/Time", (DateTime?)null, ProcessedDateTime);
                History.EvaluateChange(HistoryChanges, "Status", string.Empty, Status);
                History.EvaluateChange(HistoryChanges, "Status Message", string.Empty, StatusMessage);

                int?batchId = Batch != null ? Batch.Id : BatchId;
                if (batchId.HasValue)
                {
                    BatchHistoryChanges.Add(batchId.Value, new List <string> {
                            string.Format("Added <span class='field-name'>{0:C2}</span> transaction for <span class='field-value'>{1}</span>.", this.TotalAmount, person)
                        });
                }

                break;
            }

            case System.Data.Entity.EntityState.Modified:
            {
                string origPerson = History.GetValue <PersonAlias>(null, entry.OriginalValues["AuthorizedPersonAliasId"].ToStringSafe().AsIntegerOrNull(), rockContext);
                string person     = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);
                History.EvaluateChange(HistoryChanges, "Authorized Person", origPerson, person);

                int?origBatchId = entry.OriginalValues["BatchId"].ToStringSafe().AsIntegerOrNull();
                int?batchId     = Batch != null ? Batch.Id : BatchId;
                if (!batchId.Equals(origBatchId))
                {
                    string origBatch = History.GetValue <FinancialBatch>(null, origBatchId, rockContext);
                    string batch     = History.GetValue <FinancialBatch>(Batch, BatchId, rockContext);
                    History.EvaluateChange(HistoryChanges, "Batch", origBatch, batch);
                }

                int?origGatewayId = entry.OriginalValues["FinancialGatewayId"].ToStringSafe().AsIntegerOrNull();
                if (!FinancialGatewayId.Equals(origGatewayId))
                {
                    History.EvaluateChange(HistoryChanges, "Gateway", History.GetValue <FinancialGateway>(null, origGatewayId, rockContext), History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                }

                History.EvaluateChange(HistoryChanges, "Transaction Date/Time", entry.OriginalValues["TransactionDateTime"].ToStringSafe().AsDateTime(), TransactionDateTime);
                History.EvaluateChange(HistoryChanges, "Transaction Code", entry.OriginalValues["TransactionCode"].ToStringSafe(), TransactionCode);
                History.EvaluateChange(HistoryChanges, "Summary", entry.OriginalValues["Summary"].ToStringSafe(), Summary);
                History.EvaluateChange(HistoryChanges, "Type", entry.OriginalValues["TransactionTypeValueId"].ToStringSafe().AsIntegerOrNull(), TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChanges, "Source", entry.OriginalValues["SourceTypeValueId"].ToStringSafe().AsIntegerOrNull(), SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChanges, "Scheduled Transaction Id", entry.OriginalValues["ScheduledTransactionId"].ToStringSafe().AsIntegerOrNull(), ScheduledTransactionId);
                History.EvaluateChange(HistoryChanges, "Processed By", entry.OriginalValues["ProcessedByPersonAliasId"].ToStringSafe().AsIntegerOrNull(), ProcessedByPersonAlias, ProcessedByPersonAliasId, rockContext);
                History.EvaluateChange(HistoryChanges, "Processed Date/Time", entry.OriginalValues["ProcessedDateTime"].ToStringSafe().AsDateTime(), ProcessedDateTime);
                History.EvaluateChange(HistoryChanges, "Status", entry.OriginalValues["Status"].ToStringSafe(), Status);
                History.EvaluateChange(HistoryChanges, "Status Message", entry.OriginalValues["StatusMessage"].ToStringSafe(), StatusMessage);

                if (!batchId.Equals(origBatchId))
                {
                    if (origBatchId.HasValue)
                    {
                        BatchHistoryChanges.Add(origBatchId.Value, new List <string> {
                                string.Format("Removed <span class='field-name'>{0:C2}</span> transaction for <span class='field-value'>{1}</span>.", this.TotalAmount, person)
                            });
                    }
                    if (batchId.HasValue)
                    {
                        BatchHistoryChanges.Add(batchId.Value, new List <string> {
                                string.Format("Added <span class='field-name'>{0:C2}</span> transaction for <span class='field-value'>{1}</span>.", this.TotalAmount, person)
                            });
                    }
                }
                else
                {
                    if (batchId.HasValue)
                    {
                        BatchHistoryChanges.Add(batchId.Value, new List <string> {
                                string.Format("Updated <span class='field-name'>Transaction</span> ID: <span class='field-value'>{0}</span>.", Id)
                            });
                    }
                }
                break;
            }

            case System.Data.Entity.EntityState.Deleted:
            {
                HistoryChanges.Add("Deleted Transaction");

                int?batchId = Batch != null ? Batch.Id : BatchId;
                if (batchId.HasValue)
                {
                    string batch  = History.GetValue <FinancialBatch>(Batch, BatchId, rockContext);
                    string person = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);
                    BatchHistoryChanges.Add(batchId.Value, new List <string> {
                            string.Format("Deleted <span class='field-name'>{0:C2}</span> transaction for <span class='field-value'>{1}</span>.", this.TotalAmount, person)
                        });
                }

                // since images have a cascade delete relationship, make sure the PreSaveChanges gets called
                var childImages = new FinancialTransactionImageService(dbContext as RockContext).Queryable().Where(a => a.TransactionId == this.Id);
                foreach (var image in childImages)
                {
                    image.PreSaveChanges(dbContext, entry.State);
                }
                break;
            }
            }

            base.PreSaveChanges(dbContext, entry);
        }
コード例 #4
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The database entity entry.</param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, DbEntityEntry entry)
        {
            var rockContext = (RockContext)dbContext;

            HistoryChangeList = new History.HistoryChangeList();

            switch (entry.State)
            {
            case EntityState.Added:
            {
                HistoryChangeList.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "Transaction");

                string person = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);

                History.EvaluateChange(HistoryChangeList, "Authorized Person", string.Empty, person);
                History.EvaluateChange(HistoryChangeList, "Gateway", string.Empty, History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                History.EvaluateChange(HistoryChangeList, "Gateway Schedule Id", string.Empty, GatewayScheduleId);
                History.EvaluateChange(HistoryChangeList, "Transaction Code", string.Empty, TransactionCode);
                History.EvaluateChange(HistoryChangeList, "Summary", string.Empty, Summary);
                History.EvaluateChange(HistoryChangeList, "Type", (null as int?), TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Source", (null as int?), SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Frequency", (null as int?), TransactionFrequencyValue, TransactionFrequencyValueId);
                History.EvaluateChange(HistoryChangeList, "Start Date", (null as DateTime? ), StartDate);
                History.EvaluateChange(HistoryChangeList, "End Date", (null as DateTime? ), EndDate);
                History.EvaluateChange(HistoryChangeList, "Number of Payments", (null as int?), NumberOfPayments);
                History.EvaluateChange(HistoryChangeList, "Is Active", (null as bool?), IsActive);
                History.EvaluateChange(HistoryChangeList, "Card Reminder Date", (null as DateTime? ), CardReminderDate);
                History.EvaluateChange(HistoryChangeList, "Last Reminded Date", (null as DateTime? ), LastRemindedDate);
                var isOrganizationCurrency = new RockCurrencyCodeInfo(ForeignCurrencyCodeValueId).IsOrganizationCurrency;
                if (!isOrganizationCurrency)
                {
                    History.EvaluateChange(HistoryChangeList, "Currency Code", (null as int?), ForeignCurrencyCodeValue, ForeignCurrencyCodeValueId);
                }

                break;
            }

            case EntityState.Modified:
            {
                string origPerson = History.GetValue <PersonAlias>(null, entry.OriginalValues["AuthorizedPersonAliasId"].ToStringSafe().AsIntegerOrNull(), rockContext);
                string person     = History.GetValue <PersonAlias>(AuthorizedPersonAlias, AuthorizedPersonAliasId, rockContext);
                History.EvaluateChange(HistoryChangeList, "Authorized Person", origPerson, person);

                int?origGatewayId = entry.OriginalValues["FinancialGatewayId"].ToStringSafe().AsIntegerOrNull();
                if (!FinancialGatewayId.Equals(origGatewayId))
                {
                    History.EvaluateChange(HistoryChangeList, "Gateway", History.GetValue <FinancialGateway>(null, origGatewayId, rockContext), History.GetValue <FinancialGateway>(FinancialGateway, FinancialGatewayId, rockContext));
                }

                History.EvaluateChange(HistoryChangeList, "Gateway Schedule Id", entry.OriginalValues["GatewayScheduleId"].ToStringSafe(), GatewayScheduleId);
                History.EvaluateChange(HistoryChangeList, "Transaction Code", entry.OriginalValues["TransactionCode"].ToStringSafe(), TransactionCode);
                History.EvaluateChange(HistoryChangeList, "Summary", entry.OriginalValues["Summary"].ToStringSafe(), Summary);
                History.EvaluateChange(HistoryChangeList, "Type", entry.OriginalValues["TransactionTypeValueId"].ToStringSafe().AsIntegerOrNull(), TransactionTypeValue, TransactionTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Source", entry.OriginalValues["SourceTypeValueId"].ToStringSafe().AsIntegerOrNull(), SourceTypeValue, SourceTypeValueId);
                History.EvaluateChange(HistoryChangeList, "Frequency", entry.OriginalValues["TransactionFrequencyValueId"].ToStringSafe().AsIntegerOrNull(), TransactionFrequencyValue, TransactionFrequencyValueId);
                History.EvaluateChange(HistoryChangeList, "Start Date", entry.OriginalValues["StartDate"].ToStringSafe().AsDateTime(), StartDate);
                History.EvaluateChange(HistoryChangeList, "End Date", entry.OriginalValues["EndDate"].ToStringSafe().AsDateTime(), EndDate);
                History.EvaluateChange(HistoryChangeList, "Number of Payments", entry.OriginalValues["EndDate"].ToStringSafe().AsIntegerOrNull(), NumberOfPayments);
                History.EvaluateChange(HistoryChangeList, "Is Active", entry.OriginalValues["IsActive"].ToStringSafe().AsBooleanOrNull(), IsActive);
                History.EvaluateChange(HistoryChangeList, "Card Reminder Date", entry.OriginalValues["CardReminderDate"].ToStringSafe().AsDateTime(), CardReminderDate);
                History.EvaluateChange(HistoryChangeList, "Last Reminded Date", entry.OriginalValues["LastRemindedDate"].ToStringSafe().AsDateTime(), LastRemindedDate);
                History.EvaluateChange(HistoryChangeList, "Currency Code", entry.OriginalValues["ForeignCurrencyCodeValueId"].ToStringSafe().AsIntegerOrNull(), ForeignCurrencyCodeValue, ForeignCurrencyCodeValueId);

                break;
            }

            case EntityState.Deleted:
            {
                HistoryChangeList.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Transaction");

                // If a FinancialPaymentDetail was linked to this FinancialScheduledTransaction and is now orphaned, delete it.
                var financialPaymentDetailService = new FinancialPaymentDetailService(rockContext);
                financialPaymentDetailService.DeleteOrphanedFinancialPaymentDetail(entry);

                break;
            }
            }

            base.PreSaveChanges(dbContext, entry);
        }