/// <summary> /// Handles the Click event of the DeleteInstance 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 DeleteInstance_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { RockContext rockContext = new RockContext(); RegistrationInstanceService instanceService = new RegistrationInstanceService(rockContext); RegistrationInstance instance = instanceService.Get(e.RowKeyId); if (instance != null) { string errorMessage; if (!instanceService.CanDelete(instance, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } rockContext.WrapTransaction(() => { new RegistrationService(rockContext).DeleteRange(instance.Registrations); instanceService.Delete(instance); rockContext.SaveChanges(); }); } BindInstancesGrid(); }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e) { using (var rockContext = new RockContext()) { var service = new RegistrationInstanceService(rockContext); var registrationInstance = service.Get(hfRegistrationInstanceId.Value.AsInteger()); if (registrationInstance != null) { int registrationTemplateId = registrationInstance.RegistrationTemplateId; if (UserCanEdit || registrationInstance.IsAuthorized(Authorization.EDIT, CurrentPerson) || registrationInstance.IsAuthorized(Authorization.ADMINISTRATE, this.CurrentPerson)) { rockContext.WrapTransaction(() => { new RegistrationService(rockContext).DeleteRange(registrationInstance.Registrations); service.Delete(registrationInstance); rockContext.SaveChanges(); }); var qryParams = new Dictionary <string, string> { { PageParameterKey.RegistrationTemplateId, registrationTemplateId.ToString() } }; NavigateToParentPage(qryParams); } else { mdDeleteWarning.Show("You are not authorized to delete this registration instance.", ModalAlertType.Information); return; } } } }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e ) { using ( var rockContext = new RockContext() ) { var service = new RegistrationInstanceService( rockContext ); var registrationInstance = service.Get( hfRegistrationInstanceId.Value.AsInteger() ); if ( registrationInstance != null ) { int registrationTemplateId = registrationInstance.RegistrationTemplateId; if ( !registrationInstance.IsAuthorized( Authorization.ADMINISTRATE, this.CurrentPerson ) ) { mdDeleteWarning.Show( "You are not authorized to delete this registration instance.", ModalAlertType.Information ); return; } rockContext.WrapTransaction( () => { new RegistrationService( rockContext ).DeleteRange( registrationInstance.Registrations ); service.Delete( registrationInstance ); rockContext.SaveChanges(); } ); var qryParams = new Dictionary<string, string> { { "RegistrationTemplateId", registrationTemplateId.ToString() } }; NavigateToParentPage( qryParams ); } } }
/// <summary> /// Handles the Click event of the DeleteInstance 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 DeleteInstance_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e ) { RockContext rockContext = new RockContext(); RegistrationInstanceService instanceService = new RegistrationInstanceService( rockContext ); RegistrationInstance instance = instanceService.Get( e.RowKeyId ); if ( instance != null ) { string errorMessage; if ( !instanceService.CanDelete( instance, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } rockContext.WrapTransaction( () => { new RegistrationService( rockContext ).DeleteRange( instance.Registrations ); instanceService.Delete( instance ); rockContext.SaveChanges(); } ); } BindInstancesGrid(); }