Rock.Web.UI.Controls.NoteControl.lbDeleteNote_Click C# (CSharp) Method

lbDeleteNote_Click() protected method

Handles the Click event of the lbDeleteNote control.
protected lbDeleteNote_Click ( object sender, EventArgs e ) : void
sender object The source of the event.
e EventArgs The instance containing the event data.
return void
        protected void lbDeleteNote_Click( object sender, EventArgs e )
        {
            var rockPage = this.Page as RockPage;
            if ( rockPage != null )
            {
                var currentPerson = rockPage.CurrentPerson;

                var rockContext = new RockContext();
                var service = new NoteService( rockContext );
                Note note = null;

                if ( NoteId.HasValue )
                {
                    note = service.Get( NoteId.Value );
                    if ( note != null && note.NoteType.UserSelectable && note.IsAuthorized( Authorization.EDIT, currentPerson ) )
                    {
                        service.Delete( note );
                        rockContext.SaveChanges();
                    }
                }

                if ( DeleteButtonClick != null )
                {
                    DeleteButtonClick( this, new NoteEventArgs( NoteId ) );
                }

            }
        }