public Get ( int personId, int givingGroupId, bool includeInactive ) : IQueryable |
||
personId | int | The person identifier. |
givingGroupId | int | The giving group identifier. |
includeInactive | bool | if set to |
return | IQueryable |
protected void bbtnDelete_Click( object sender, EventArgs e ) { BootstrapButton bbtnDelete = (BootstrapButton)sender; RepeaterItem riItem = (RepeaterItem)bbtnDelete.NamingContainer; HiddenField hfScheduledTransactionId = (HiddenField)riItem.FindControl( "hfScheduledTransactionId" ); Literal content = (Literal)riItem.FindControl( "lLiquidContent" ); Button btnEdit = (Button)riItem.FindControl( "btnEdit" ); var rockContext = new Rock.Data.RockContext(); FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService( rockContext ); var currentTransaction = fstService.Get( Int32.Parse(hfScheduledTransactionId.Value) ); string errorMessage = string.Empty; if ( fstService.Cancel( currentTransaction, out errorMessage ) ) { rockContext.SaveChanges(); content.Text = String.Format( "<div class='alert alert-success'>Your recurring {0} has been deleted.</div>", GetAttributeValue( "TransactionLabel" ).ToLower() ); } else { content.Text = String.Format( "<div class='alert alert-danger'>An error occured while deleting your scheduled transation. Message: {0}</div>", errorMessage ); } bbtnDelete.Visible = false; btnEdit.Visible = false; }
private void DeleteOldTransaction( int scheduledTransactionId ) { using ( var rockContext = new Rock.Data.RockContext() ) { FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService( rockContext ); var currentTransaction = fstService.Get( scheduledTransactionId ); if ( currentTransaction != null && currentTransaction.FinancialGateway != null ) { currentTransaction.FinancialGateway.LoadAttributes( rockContext ); } string errorMessage = string.Empty; if ( fstService.Cancel( currentTransaction, out errorMessage ) ) { try { fstService.GetStatus( currentTransaction, out errorMessage ); } catch { } rockContext.SaveChanges(); //content.Text = String.Format( "<div class='alert alert-success'>Your recurring {0} has been deleted.</div>", GetAttributeValue( "TransactionLabel" ).ToLower() ); } else { //content.Text = String.Format( "<div class='alert alert-danger'>An error occured while deleting your scheduled transation. Message: {0}</div>", errorMessage ); } } }
/// <summary> /// Processes the confirmation. /// </summary> /// <param name="errorMessage">The error message.</param> /// <returns></returns> private bool ProcessConfirmation( out string errorMessage ) { errorMessage = string.Empty; if ( string.IsNullOrWhiteSpace( TransactionCode ) ) { if ( Gateway == null ) { errorMessage = "There was a problem creating the payment gateway information"; return false; } using ( new UnitOfWorkScope() ) { var personService = new PersonService(); var transactionService = new FinancialScheduledTransactionService(); var transactionDetailService = new FinancialScheduledTransactionDetailService(); FinancialScheduledTransaction scheduledTransaction = null; if ( ScheduledTransactionId.HasValue ) { scheduledTransaction = transactionService.Get( ScheduledTransactionId.Value ); } if ( scheduledTransaction == null ) { errorMessage = "There was a problem getting the transaction information"; return false; } if ( scheduledTransaction.AuthorizedPerson == null ) { errorMessage = "There was a problem determining the person associated with the transaction"; return false; } // Get the payment schedule scheduledTransaction.TransactionFrequencyValueId = btnFrequency.SelectedValueAsId().Value; if ( dtpStartDate.SelectedDate.HasValue && dtpStartDate.SelectedDate > DateTime.Today ) { scheduledTransaction.StartDate = dtpStartDate.SelectedDate.Value; } else { scheduledTransaction.StartDate = DateTime.MinValue; } PaymentInfo paymentInfo = GetPaymentInfo( personService, scheduledTransaction ); if ( paymentInfo == null ) { errorMessage = "There was a problem creating the payment information"; return false; } else { } if ( Gateway.UpdateScheduledPayment( scheduledTransaction, paymentInfo, out errorMessage ) ) { var selectedAccountIds = SelectedAccounts .Where( a => a.Amount > 0 ) .Select( a => a.Id ).ToList(); var deletedAccounts = scheduledTransaction.ScheduledTransactionDetails .Where( a => !selectedAccountIds.Contains( a.AccountId ) ).ToList(); foreach ( var deletedAccount in deletedAccounts ) { scheduledTransaction.ScheduledTransactionDetails.Remove( deletedAccount ); transactionDetailService.Delete( deletedAccount, CurrentPersonId ); } foreach ( var account in SelectedAccounts ) { var detail = scheduledTransaction.ScheduledTransactionDetails .Where( d => d.AccountId == account.Id ).FirstOrDefault(); if ( detail == null ) { detail = new FinancialScheduledTransactionDetail(); detail.AccountId = account.Id; scheduledTransaction.ScheduledTransactionDetails.Add( detail ); } detail.Amount = account.Amount; } transactionService.Save( scheduledTransaction, CurrentPersonId ); ScheduleId = scheduledTransaction.GatewayScheduleId; TransactionCode = scheduledTransaction.TransactionCode; } else { return false; } tdTransactionCode.Description = TransactionCode; tdTransactionCode.Visible = !string.IsNullOrWhiteSpace( TransactionCode ); tdScheduleId.Description = ScheduleId; tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId ); return true; } } else { pnlDupWarning.Visible = true; return false; } }
/// <summary> /// Executes this instance. /// </summary> public void Execute() { using ( var rockContext = new RockContext() ) { var gateway = new FinancialGatewayService( rockContext ).Get( GatewayId ); if ( gateway != null ) { var gatewayComponent = gateway.GetGatewayComponent(); if ( gatewayComponent != null ) { var scheduledTxnService = new FinancialScheduledTransactionService( rockContext ); foreach( var txnId in ScheduledTransactionIds ) { var scheduledTxn = scheduledTxnService.Get( txnId ); if ( scheduledTxn != null ) { string statusMsgs = string.Empty; gatewayComponent.GetScheduledPaymentStatus( scheduledTxn, out statusMsgs ); rockContext.SaveChanges(); } } } } } }
/// <summary> /// Processes the confirmation. /// </summary> /// <param name="errorMessage">The error message.</param> /// <returns></returns> private bool ProcessConfirmation( out string errorMessage ) { var rockContext = new RockContext(); errorMessage = string.Empty; if ( string.IsNullOrWhiteSpace( TransactionCode ) ) { if ( Gateway == null ) { errorMessage = "There was a problem creating the payment gateway information"; return false; } var personService = new PersonService( rockContext ); var transactionService = new FinancialScheduledTransactionService( rockContext ); var transactionDetailService = new FinancialScheduledTransactionDetailService( rockContext ); FinancialScheduledTransaction scheduledTransaction = null; if ( ScheduledTransactionId.HasValue ) { scheduledTransaction = transactionService.Get( ScheduledTransactionId.Value ); } if ( scheduledTransaction == null ) { errorMessage = "There was a problem getting the transaction information"; return false; } if ( scheduledTransaction.AuthorizedPerson == null ) { errorMessage = "There was a problem determining the person associated with the transaction"; return false; } var changeSummary = new StringBuilder(); // Get the payment schedule scheduledTransaction.TransactionFrequencyValueId = btnFrequency.SelectedValueAsId().Value; changeSummary.Append( DefinedValueCache.Read( scheduledTransaction.TransactionFrequencyValueId, rockContext ) ); if ( dtpStartDate.SelectedDate.HasValue && dtpStartDate.SelectedDate > RockDateTime.Today ) { scheduledTransaction.StartDate = dtpStartDate.SelectedDate.Value; changeSummary.AppendFormat( " starting {0}", scheduledTransaction.StartDate.ToShortDateString() ); } else { scheduledTransaction.StartDate = DateTime.MinValue; } changeSummary.AppendLine(); PaymentInfo paymentInfo = GetPaymentInfo( personService, scheduledTransaction ); if ( paymentInfo == null ) { errorMessage = "There was a problem creating the payment information"; return false; } else { } // If transaction is not active, attempt to re-activate it first if ( !scheduledTransaction.IsActive ) { if ( !transactionService.Reactivate( scheduledTransaction, out errorMessage ) ) { return false; } } if ( Gateway.UpdateScheduledPayment( scheduledTransaction, paymentInfo, out errorMessage ) ) { if ( paymentInfo.CurrencyTypeValue != null ) { changeSummary.Append( paymentInfo.CurrencyTypeValue.Value ); scheduledTransaction.CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; DefinedValueCache creditCardTypeValue = paymentInfo.CreditCardTypeValue; if ( creditCardTypeValue != null ) { changeSummary.AppendFormat( " - {0}", creditCardTypeValue.Value ); scheduledTransaction.CreditCardTypeValueId = creditCardTypeValue.Id; } else { scheduledTransaction.CreditCardTypeValueId = null; } changeSummary.AppendFormat( " {0}", paymentInfo.MaskedNumber ); changeSummary.AppendLine(); } var selectedAccountIds = SelectedAccounts .Where( a => a.Amount > 0 ) .Select( a => a.Id ).ToList(); var deletedAccounts = scheduledTransaction.ScheduledTransactionDetails .Where( a => !selectedAccountIds.Contains( a.AccountId ) ).ToList(); foreach ( var deletedAccount in deletedAccounts ) { scheduledTransaction.ScheduledTransactionDetails.Remove( deletedAccount ); transactionDetailService.Delete( deletedAccount ); } foreach ( var account in SelectedAccounts ) { var detail = scheduledTransaction.ScheduledTransactionDetails .Where( d => d.AccountId == account.Id ).FirstOrDefault(); if ( detail == null ) { detail = new FinancialScheduledTransactionDetail(); detail.AccountId = account.Id; scheduledTransaction.ScheduledTransactionDetails.Add( detail ); } detail.Amount = account.Amount; changeSummary.AppendFormat( "{0}: {1:C2}", account.Name, account.Amount ); changeSummary.AppendLine(); } rockContext.SaveChanges(); // Add a note about the change var noteTypeService = new NoteTypeService( rockContext ); var noteType = noteTypeService.Get( scheduledTransaction.TypeId, "Note" ); var noteService = new NoteService( rockContext ); var note = new Note(); note.NoteTypeId = noteType.Id; note.EntityId = scheduledTransaction.Id; note.Caption = "Updated Transaction"; note.Text = changeSummary.ToString(); noteService.Add( note ); rockContext.SaveChanges(); ScheduleId = scheduledTransaction.GatewayScheduleId; TransactionCode = scheduledTransaction.TransactionCode; if (transactionService.GetStatus( scheduledTransaction, out errorMessage )) { rockContext.SaveChanges(); } } else { return false; } tdTransactionCode.Description = TransactionCode; tdTransactionCode.Visible = !string.IsNullOrWhiteSpace( TransactionCode ); tdScheduleId.Description = ScheduleId; tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId ); return true; } else { pnlDupWarning.Visible = true; return false; } }
/// <summary> /// Handles the Click event of the lbCancel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbCancel_Click( object sender, EventArgs e ) { int? txnId = PageParameter( "ScheduledTransactionId" ).AsIntegerOrNull(); if ( txnId.HasValue ) { var rockContext = new RockContext(); var txnService = new FinancialScheduledTransactionService( rockContext ); var txn = txnService.Get( txnId.Value ); if ( txn != null ) { string errorMessage = string.Empty; if ( txnService.Cancel( txn, out errorMessage ) ) { txnService.GetStatus( txn, out errorMessage ); rockContext.SaveChanges(); } else { ShowErrorMessage( errorMessage ); } ShowView( txn ); } } }