/// <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) { // First remove it from Subsplash gCommunication_Remove(sender, e); var rockContext = new RockContext(); var communicationService = new CommunicationService(rockContext); 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); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Remove 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_Remove(object sender, Rock.Web.UI.Controls.RowEventArgs e) { var rockContext = new RockContext(); var communicationService = new CommunicationService(rockContext); var communication = communicationService.Get(e.RowKeyId); if (communication != null) { string errorMessage; if (!communicationService.CanDelete(communication, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } if (!communication.ForeignGuid.HasValue) { mdGridWarning.Show("Unable to delete this communication from Subsplash. The ForeignGuid is missing.", ModalAlertType.Warning); return; } // Load the notifications using the Push Notifications Transport var transport = TransportContainer.Instance.Components.FirstOrDefault(t => t.Value.Value.TypeGuid == GetAttributeValue("Transport").AsGuidOrNull()).Value.Value; if (transport != null) { transport.LoadAttributes(); var client = new RestClient(transport.GetAttributeValue("APIEndpoint")); var pushNotificationRequest = new RestRequest("notifications/{id}", Method.DELETE); pushNotificationRequest.AddHeader("Content-Type", "application/json"); pushNotificationRequest.AddHeader("Authorization", "Bearer " + Encryption.DecryptString(transport.GetAttributeValue("JWTToken"))); pushNotificationRequest.AddParameter("id", communication.ForeignGuid.ToString(), ParameterType.UrlSegment); pushNotificationRequest.RequestFormat = DataFormat.Json; var response = client.Execute(pushNotificationRequest); } } BindGrid(); }
/// <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(); }