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

lbSaveNote_Click() protected method

Handles the Click event of the lbSaveNote control.
protected lbSaveNote_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 lbSaveNote_Click( object sender, EventArgs e )
        {
            if ( _ddlNoteType.Visible )
            {
                NoteTypeId = _ddlNoteType.SelectedValueAsInt() ?? 0;
            }

            var rockPage = this.Page as RockPage;
            if (rockPage != null && NoteTypeId.HasValue)
            {
                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 = new Note();
                    note.IsSystem = false;
                    note.EntityId = EntityId;
                    service.Add( note );
                }

                note.NoteTypeId = NoteTypeId.Value;
                if ( string.IsNullOrWhiteSpace( note.Caption ) )
                {
                    note.Caption = IsPrivate ? "You - Personal Note" : string.Empty;
                }
                note.Text = Text;
                note.IsAlert = IsAlert;
                note.IsPrivateNote = IsPrivate;

                if (ShowCreateDateInput)
                {
                    note.CreatedDateTime = _dtCreateDate.SelectedDateTime;
                }

                rockContext.SaveChanges();

                if ( SaveButtonClick != null )
                {
                    SaveButtonClick( this, new NoteEventArgs( note.Id ) );
                }
            }
        }