/// <summary> /// Cancels the specified scheduled transaction. /// </summary> /// <param name="scheduledTransaction">The scheduled transaction.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public bool Cancel(FinancialScheduledTransaction scheduledTransaction, out string errorMessages) { if (scheduledTransaction.GatewayEntityType != null) { var gateway = Rock.Financial.GatewayContainer.GetComponent(scheduledTransaction.GatewayEntityType.Guid.ToString()); if (gateway != null && gateway.IsActive) { if (gateway.CancelScheduledPayment(scheduledTransaction, out errorMessages)) { var noteTypeService = new NoteTypeService((RockContext)this.Context); var noteType = noteTypeService.Get(scheduledTransaction.TypeId, "Note"); var noteService = new NoteService((RockContext)this.Context); var note = new Note(); note.NoteTypeId = noteType.Id; note.EntityId = scheduledTransaction.Id; note.Caption = "Cancelled Transaction"; noteService.Add(note); return(true); } else { return(false); } } } errorMessages = "Gateway is invalid or not active"; return(false); }
/// <summary> /// Gets the specified entity type identifier. /// </summary> /// <param name="entityTypeId">The entity type identifier.</param> /// <param name="name">The name.</param> /// <param name="create">if set to <c>true</c> [create].</param> /// <returns></returns> public NoteType Get(int entityTypeId, string name, bool create = true) { var noteTypes = Get(entityTypeId, string.Empty, string.Empty).ToList(); var noteType = noteTypes.Where(t => t.Name == name).FirstOrDefault(); if (noteType == null && create) { noteType = new NoteType(); noteType.IsSystem = false; noteType.EntityTypeId = entityTypeId; noteType.EntityTypeQualifierColumn = string.Empty; noteType.EntityTypeQualifierValue = string.Empty; noteType.Name = name; noteType.UserSelectable = true; noteType.IconCssClass = string.Empty; noteType.CssClass = string.Empty; noteType.Order = noteTypes.Any() ? noteTypes.Max(t => t.Order) + 1 : 0; // Create a new context/service so that save does not affect calling method's context using (var rockContext = new RockContext()) { var noteTypeService = new NoteTypeService(rockContext); noteTypeService.Add(noteType); rockContext.SaveChanges(); } // requery using calling context noteType = Get(noteType.Id); } return(noteType); }
/// <summary> /// Gets the first <see cref="Rock.Model.NoteType" /> by Name and EntityType /// </summary> /// <param name="entityTypeId">A <see cref="System.Int32" /> representing the Id of the <see cref="Rock.Model.EntityType" /> to search for.</param> /// <param name="name">A <see cref="System.String" /> representing the Name of the</param> /// <param name="create">if set to <c>true</c> [create].</param> /// <returns> /// The first <see cref="Rock.Model.NoteType" /> matching the provided values. If a match is not found, this value will be null. /// </returns> public NoteType Get(int entityTypeId, string name, bool create = true) { var noteType = Queryable().FirstOrDefault(n => n.EntityTypeId == entityTypeId && n.Name == name); if (noteType == null && create) { noteType = new NoteType(); noteType.IsSystem = false; noteType.EntityTypeId = entityTypeId; noteType.EntityTypeQualifierColumn = string.Empty; noteType.EntityTypeQualifierValue = string.Empty; noteType.Name = name; // Create a new context/service so that save does not affect calling method's context var rockContext = new RockContext(); var noteTypeService = new NoteTypeService(rockContext); noteTypeService.Add(noteType); rockContext.SaveChanges(); // requery using calling context noteType = Get(noteType.Id); } return(noteType); }
private static NoteTypeCache LoadById2(int id, RockContext rockContext) { var NoteTypeService = new Rock.Model.NoteTypeService(rockContext); var NoteTypeModel = NoteTypeService.Get(id); if (NoteTypeModel != null) { return(new NoteTypeCache(NoteTypeModel)); } return(null); }
/// <summary> /// Cancels the specified scheduled transaction. /// </summary> /// <param name="scheduledTransaction">The scheduled transaction.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public bool Cancel( FinancialScheduledTransaction scheduledTransaction, out string errorMessages ) { if ( scheduledTransaction != null && scheduledTransaction.FinancialGateway != null && scheduledTransaction.FinancialGateway.IsActive ) { if ( scheduledTransaction.FinancialGateway.Attributes == null ) { scheduledTransaction.FinancialGateway.LoadAttributes( (RockContext)this.Context ); } var gateway = scheduledTransaction.FinancialGateway.GetGatewayComponent(); if ( gateway != null ) { if ( gateway.CancelScheduledPayment( scheduledTransaction, out errorMessages ) ) { var noteTypeService = new NoteTypeService( (RockContext)this.Context ); var noteType = noteTypeService.Get( Rock.SystemGuid.NoteType.SCHEDULED_TRANSACTION_NOTE.AsGuid() ); if ( noteType != null ) { var noteService = new NoteService( (RockContext)this.Context ); var note = new Note(); note.NoteTypeId = noteType.Id; note.EntityId = scheduledTransaction.Id; note.Caption = "Cancelled Transaction"; noteService.Add( note ); } return true; } else { return false; } } } errorMessages = "Gateway is invalid or not active"; return false; }