Beispiel #1
0
        /// <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();
        }
Beispiel #2
0
        /// <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();
        }