/// <summary> /// Handles the Delete event of the gCommunication control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param> protected void gCommunication_Delete( object sender, Rock.Web.UI.Controls.RowEventArgs e ) { RockTransactionScope.WrapTransaction( () => { var communicationService = new CommunicationService(); var communication = communicationService.Get( e.RowKeyId ); if ( communication != null ) { string errorMessage; if ( !communicationService.CanDelete( communication, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } communicationService.Delete( communication, CurrentPersonId ); communicationService.Save( communication, CurrentPersonId ); } } ); BindGrid(); }
/// <summary> /// Handles the Click event of the btnCopy 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 btnCopy_Click( object sender, EventArgs e ) { using ( new UnitOfWorkScope() ) { var service = new CommunicationService(); var communication = UpdateCommunication( service ); if ( communication != null ) { var newCommunication = communication.Clone( false ); newCommunication.Id = 0; newCommunication.Guid = Guid.Empty; newCommunication.SenderPersonId = CurrentPersonId; newCommunication.Status = CommunicationStatus.Transient; newCommunication.ReviewerPersonId = null; newCommunication.ReviewedDateTime = null; newCommunication.ReviewerNote = string.Empty; communication.Recipients.ToList().ForEach( r => newCommunication.Recipients.Add( new CommunicationRecipient() { PersonId = r.PersonId, Status = CommunicationRecipientStatus.Pending, StatusNote = string.Empty } ) ); service.Add( newCommunication, CurrentPersonId ); service.Save( newCommunication, CurrentPersonId ); // Redirect to new communication if ( CurrentPageReference.Parameters.ContainsKey( "CommunicationId" ) ) { CurrentPageReference.Parameters["CommunicationId"] = newCommunication.Id.ToString(); } else { CurrentPageReference.Parameters.Add( "CommunicationId", newCommunication.Id.ToString() ); } Response.Redirect( CurrentPageReference.BuildUrl() ); Context.ApplicationInstance.CompleteRequest(); } } }
/// <summary> /// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { if ( CommunicationId.HasValue ) { var service = new CommunicationService(); var communication = service.Get( CommunicationId.Value ); if ( communication != null ) { var prevStatus = communication.Status; communication.Recipients .Where( r => r.Status == CommunicationRecipientStatus.Pending ) .ToList() .ForEach( r => r.Status = CommunicationRecipientStatus.Cancelled ); // Save and re-read communication to reload recipient statuses service.Save( communication, CurrentPersonId ); communication = service.Get( communication.Id ); if ( !communication.Recipients .Where( r => r.Status == CommunicationRecipientStatus.Success ) .Any() ) { communication.Status = CommunicationStatus.Draft; } ShowResult( "The communication has been cancelled", communication ); } } } }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { using ( new UnitOfWorkScope() ) { var service = new CommunicationService(); var communication = UpdateCommunication( service ); if ( communication != null ) { var prevStatus = communication.Status; if ( communication.Status == CommunicationStatus.Transient ) { communication.Status = CommunicationStatus.Draft; } service.Save( communication, CurrentPersonId ); ShowResult( "The communication has been saved", communication ); } } } }
/// <summary> /// Handles the Click event of the btnDeny 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 btnDeny_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { using ( new UnitOfWorkScope() ) { var service = new CommunicationService(); var communication = UpdateCommunication( service ); if ( communication != null ) { var prevStatus = communication.Status; if ( IsUserAuthorized( "Approve" ) ) { communication.Status = CommunicationStatus.Denied; communication.ReviewedDateTime = DateTime.Now; communication.ReviewerPersonId = CurrentPersonId; } service.Save( communication, CurrentPersonId ); // TODO: Send notice to sneder that communication was denied ShowResult( "The communicaiton has been denied", communication ); } } } }
/// <summary> /// Handles the Click event of the btnSubmit 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 btnSubmit_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { using ( new UnitOfWorkScope() ) { var service = new CommunicationService(); var communication = UpdateCommunication( service ); if ( communication != null ) { string message = string.Empty; var prevStatus = communication.Status; if ( CheckApprovalRequired( communication.Recipients.Count ) && !IsUserAuthorized( "Approve" ) ) { communication.Status = CommunicationStatus.Submitted; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = DateTime.Now; communication.ReviewerPersonId = CurrentPersonId; message = "Communication has been queued for sending."; // TODO: Send notice to sender that communication was approved } communication.Recipients .Where( r => r.Status == CommunicationRecipientStatus.Cancelled || r.Status == CommunicationRecipientStatus.Failed ) .ToList() .ForEach( r => { r.Status = CommunicationRecipientStatus.Pending; r.StatusNote = string.Empty; } ); service.Save( communication, CurrentPersonId ); if ( communication.Status == CommunicationStatus.Approved ) { bool sendNow = false; if ( bool.TryParse( GetAttributeValue( "SendWhenApproved" ), out sendNow ) && sendNow ) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonId = CurrentPersonId; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction ); } } ShowResult( message, communication ); } } } }