/// <summary> /// Handles the Click event of the lbDelete 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 lbDelete_Click(object sender, EventArgs e) { int prayerRequestId = hfPrayerRequestId.ValueAsInt(); if (!IsUserAuthorized(Authorization.EDIT)) { maWarning.Show("You are not authorized to delete this request.", ModalAlertType.Information); return; } var rockContext = new RockContext(); PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext); PrayerRequest prayerRequest = prayerRequestService.Get(prayerRequestId); if (prayerRequest != null) { DeleteAllRelatedNotes(prayerRequest, rockContext); string errorMessage; if (!prayerRequestService.CanDelete(prayerRequest, out errorMessage)) { maWarning.Show(errorMessage, ModalAlertType.Information); return; } prayerRequestService.Delete(prayerRequest); rockContext.SaveChanges(); NavigateToParentPage(); } }
/// <summary> /// Handles the Delete event of the gPrayerRequests control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPrayerRequests_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { PrayerRequestService prayerRequestService = new PrayerRequestService(); PrayerRequest prayerRequest = prayerRequestService.Get((int)e.RowKeyValue); if (prayerRequest != null) { DeleteAllRelatedNotes(prayerRequest); string errorMessage; if (!prayerRequestService.CanDelete(prayerRequest, out errorMessage)) { maGridWarning.Show(errorMessage, ModalAlertType.Information); return; } prayerRequestService.Delete(prayerRequest, CurrentPersonId); prayerRequestService.Save(prayerRequest, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Handles the Delete event of the gPrayerRequests control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPrayerRequests_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext); PrayerRequest prayerRequest = prayerRequestService.Get(e.RowKeyId); if (prayerRequest != null) { DeleteAllRelatedNotes(prayerRequest, rockContext); string errorMessage; if (!prayerRequestService.CanDelete(prayerRequest, out errorMessage)) { maGridWarning.Show(errorMessage, ModalAlertType.Information); return; } prayerRequestService.Delete(prayerRequest); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Click event of the lbDelete 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 lbDelete_Click(object sender, EventArgs e) { int prayerRequestId = hfPrayerRequestId.ValueAsInt(); if (!IsUserAuthorized(Authorization.EDIT)) { maWarning.Show("You are not authorized to delete this request.", ModalAlertType.Information); return; } var rockContext = new RockContext(); PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext); PrayerRequest prayerRequest = prayerRequestService.Get(prayerRequestId); if (prayerRequest != null) { DeleteAllRelatedNotes(prayerRequest, rockContext); string errorMessage; if (!prayerRequestService.CanDelete(prayerRequest, out errorMessage)) { maWarning.Show(errorMessage, ModalAlertType.Information); return; } prayerRequestService.Delete(prayerRequest); rockContext.SaveChanges(); var queryParms = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(PageParameter("PersonId"))) { queryParms.Add("PersonId", PageParameter("PersonId")); } NavigateToParentPage(queryParms); } }
/// <summary> /// Deletes the request and returns a new set of requests. /// </summary> /// <returns> /// The response to send back to the client. /// </returns> private CallbackResponse DeleteRequest(Guid requestGuid) { using (var rockContext = new RockContext()) { var prayerRequestService = new PrayerRequestService(rockContext); var prayerRequest = prayerRequestService.Get(requestGuid); if (prayerRequest == null) { return(new CallbackResponse { Error = "We couldn't find that prayer request." }); } var canDelete = prayerRequest.RequestedByPersonAlias != null && prayerRequest.RequestedByPersonAlias.PersonId == RequestContext.CurrentPerson?.Id; if (!canDelete) { return(new CallbackResponse { Error = "You do not have permission to delete this prayer request." }); } prayerRequestService.Delete(prayerRequest); // Save all changes to database. rockContext.SaveChanges(); } return(new CallbackResponse { Content = BuildContent() }); }