Example #1
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            int noteTypeId = hfNoteTypeId.Value.AsInteger();

            var      rockContext = new RockContext();
            var      service     = new NoteTypeService(rockContext);
            NoteType noteType    = null;

            if (noteTypeId != 0)
            {
                noteType = service.Get(noteTypeId);
            }

            int entityTypeId = epEntityType.SelectedEntityTypeId ?? 0;

            if (noteType == null)
            {
                int?maxNoteTypeOrderForEntity = service.Queryable().Where(t => t.EntityTypeId == entityTypeId).Max(a => ( int? )a.Order);

                noteType       = new NoteType();
                noteType.Order = (maxNoteTypeOrderForEntity ?? 0) + 1;
                service.Add(noteType);
            }

            noteType.Name         = tbName.Text;
            noteType.EntityTypeId = entityTypeId;
            noteType.EntityTypeQualifierColumn = string.Empty;
            noteType.EntityTypeQualifierValue  = string.Empty;

            noteType.IconCssClass    = tbIconCssClass.Text;
            noteType.BackgroundColor = cpBackgroundColor.Text;
            noteType.FontColor       = cpFontColor.Text;
            noteType.BorderColor     = cpBorderColor.Text;

            noteType.UserSelectable            = cbUserSelectable.Checked;
            noteType.RequiresApprovals         = cbRequiresApprovals.Checked;
            noteType.SendApprovalNotifications = cbSendApprovalNotifications.Checked;
            noteType.AllowsWatching            = cbAllowsWatching.Checked;
            noteType.AutoWatchAuthors          = cbAutoWatchAuthors.Checked;

            noteType.AllowsReplies = cbAllowsReplies.Checked;
            noteType.MaxReplyDepth = nbMaxReplyDepth.Text.AsIntegerOrNull();

            noteType.AllowsAttachments = cbAllowsAttachments.Checked;
            noteType.BinaryFileTypeId  = noteType.AllowsAttachments ? bftpAttachmentType.SelectedValueAsId() : null;

            noteType.ApprovalUrlTemplate = ceApprovalUrlTemplate.Text;

            if (noteType.IsValid)
            {
                rockContext.SaveChanges();
            }

            NavigateToParentPage();
        }
Example #2
0
        /// <summary>
        /// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick(object sender, EventArgs e)
        {
            int noteTypeId = 0;

            if (hfIdValue.Value != string.Empty && !int.TryParse(hfIdValue.Value, out noteTypeId))
            {
                noteTypeId = 0;
            }

            var      rockContext = new RockContext();
            var      service     = new NoteTypeService(rockContext);
            NoteType noteType    = null;

            if (noteTypeId != 0)
            {
                noteType = service.Get(noteTypeId);
            }

            if (noteType == null)
            {
                var orders = service.Queryable()
                             .Where(t => t.EntityTypeId == (entityTypePicker.SelectedEntityTypeId ?? 0))
                             .Select(t => t.Order)
                             .ToList();

                noteType       = new NoteType();
                noteType.Order = orders.Any() ? orders.Max(t => t) + 1 : 0;
                service.Add(noteType);
            }

            noteType.Name         = tbName.Text;
            noteType.EntityTypeId = entityTypePicker.SelectedEntityTypeId ?? 0;
            noteType.EntityTypeQualifierColumn = "";
            noteType.EntityTypeQualifierValue  = "";
            noteType.UserSelectable            = cbUserSelectable.Checked;
            noteType.CssClass     = tbCssClass.Text;
            noteType.IconCssClass = tbIconCssClass.Text;

            if (noteType.IsValid)
            {
                rockContext.SaveChanges();

                NoteTypeCache.Flush(noteType.Id);
                NoteTypeCache.FlushEntityNoteTypes();

                hfIdValue.Value = string.Empty;
                modalDetails.Hide();

                BindFilter();
                BindGrid();
            }
        }
Example #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var contextEntity = this.ContextEntity();

            if (contextEntity != null)
            {
                string noteTypeName = GetAttributeValue("NoteType");

                var rockContext = new RockContext();
                var service     = new NoteTypeService(rockContext);
                var noteType    = service.Get(contextEntity.TypeId, noteTypeName);

                // If a note type with the specified name does not exist for the context entity type, create one
                if (noteType == null)
                {
                    noteType              = new NoteType();
                    noteType.IsSystem     = false;
                    noteType.EntityTypeId = contextEntity.TypeId;
                    noteType.EntityTypeQualifierColumn = string.Empty;
                    noteType.EntityTypeQualifierValue  = string.Empty;
                    noteType.Name = noteTypeName;
                    service.Add(noteType);
                    rockContext.SaveChanges();
                }

                notesTimeline.NoteTypeId = noteType.Id;
                notesTimeline.EntityId   = contextEntity.Id;
                notesTimeline.Title      = GetAttributeValue("Heading");
                if (string.IsNullOrWhiteSpace(notesTimeline.Title))
                {
                    notesTimeline.Title = noteType.Name;
                }
                notesTimeline.TitleIconCssClass = GetAttributeValue("HeadingIcon");
                notesTimeline.Term                = GetAttributeValue("NoteTerm");
                notesTimeline.DisplayType         = GetAttributeValue("DisplayType") == "Light" ? NoteDisplayType.Light : NoteDisplayType.Full;
                notesTimeline.UsePersonIcon       = GetAttributeValue("UsePersonIcon").AsBoolean();
                notesTimeline.ShowAlertCheckBox   = GetAttributeValue("ShowAlertCheckbox").AsBoolean();
                notesTimeline.ShowPrivateCheckBox = GetAttributeValue("ShowPrivateCheckbox").AsBoolean();
                notesTimeline.ShowSecurityButton  = GetAttributeValue("ShowSecurityButton").AsBoolean();
                notesTimeline.AllowAnonymousEntry = GetAttributeValue("Allow Anonymous").AsBoolean();
                notesTimeline.AddAlwaysVisible    = GetAttributeValue("AddAlwaysVisible").AsBoolean();
                notesTimeline.SortDirection       = GetAttributeValue("DisplayOrder") == "Ascending" ? ListSortDirection.Ascending : ListSortDirection.Descending;
            }
        }
Example #4
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );

            var contextEntity = this.ContextEntity();
            if ( contextEntity != null )
            {
                string noteTypeName = GetAttributeValue( "NoteType" );

                var rockContext = new RockContext();
                var service = new NoteTypeService( rockContext );
                var noteType = service.Get( contextEntity.TypeId, noteTypeName );

                // If a note type with the specified name does not exist for the context entity type, create one
                if ( noteType == null )
                {
                    noteType = new NoteType();
                    noteType.IsSystem = false;
                    noteType.EntityTypeId = contextEntity.TypeId;
                    noteType.EntityTypeQualifierColumn = string.Empty;
                    noteType.EntityTypeQualifierValue = string.Empty;
                    noteType.Name = noteTypeName;
                    service.Add( noteType );
                    rockContext.SaveChanges();
                }

                notesTimeline.NoteTypeId = noteType.Id;
                notesTimeline.EntityId = contextEntity.Id;
                notesTimeline.Title = GetAttributeValue( "Heading" );
                if ( string.IsNullOrWhiteSpace( notesTimeline.Title ) )
                {
                    notesTimeline.Title = noteType.Name;
                }
                notesTimeline.TitleIconCssClass = GetAttributeValue( "HeadingIcon" );
                notesTimeline.Term = GetAttributeValue( "NoteTerm" );
                notesTimeline.DisplayType = GetAttributeValue( "DisplayType" ) == "Light" ? NoteDisplayType.Light : NoteDisplayType.Full;
                notesTimeline.UsePersonIcon = GetAttributeValue( "UsePersonIcon" ).AsBoolean();
                notesTimeline.ShowAlertCheckBox = GetAttributeValue( "ShowAlertCheckbox" ).AsBoolean();
                notesTimeline.ShowPrivateCheckBox = GetAttributeValue( "ShowPrivateCheckbox" ).AsBoolean();
                notesTimeline.ShowSecurityButton = GetAttributeValue( "ShowSecurityButton" ).AsBoolean();
                notesTimeline.AllowAnonymousEntry = GetAttributeValue( "Allow Anonymous" ).AsBoolean();
                notesTimeline.AddAlwaysVisible = GetAttributeValue( "AddAlwaysVisible" ).AsBoolean();
                notesTimeline.SortDirection = GetAttributeValue( "DisplayOrder" ) == "Ascending" ? ListSortDirection.Ascending : ListSortDirection.Descending;
            }
        }
Example #5
0
        private void GetNoteType()
        {
            string noteTypeName = GetAttributeValue("NoteType");

            var service = new NoteTypeService();

            noteType = service.Get(contextEntity.TypeId, noteTypeName);

            // If a note type with the specified name does not exist for the context entity type, create one
            if (noteType == null)
            {
                noteType              = new NoteType();
                noteType.IsSystem     = false;
                noteType.EntityTypeId = contextEntity.TypeId;
                noteType.EntityTypeQualifierColumn = string.Empty;
                noteType.EntityTypeQualifierValue  = string.Empty;
                noteType.Name = noteTypeName;
                service.Add(noteType, CurrentPersonId);
                service.Save(noteType, CurrentPersonId);
            }
        }
Example #6
0
        /// <summary>
        /// Sets the type of the note.
        /// </summary>
        private void SetNoteType()
        {
            var    entityTypeId = EntityTypeCache.Read(typeof(PrayerRequest)).Id;
            string noteTypeName = GetAttributeValue("NoteType");

            var rockContext = new RockContext();
            var service     = new NoteTypeService(rockContext);
            var noteType    = service.Get(entityTypeId, noteTypeName);

            // If a note type with the specified name does not exist, create one
            if (noteType == null)
            {
                noteType              = new NoteType();
                noteType.IsSystem     = false;
                noteType.EntityTypeId = entityTypeId;
                noteType.EntityTypeQualifierColumn = string.Empty;
                noteType.EntityTypeQualifierValue  = string.Empty;
                noteType.Name = noteTypeName;
                service.Add(noteType);
                rockContext.SaveChanges();
            }

            NoteTypeId = noteType.Id;
        }
Example #7
0
        /// <summary>
        /// Maps the notes.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        public void MapNotes( IQueryable<Row> tableData )
        {
            var lookupContext = new RockContext();
            var categoryService = new CategoryService( lookupContext );
            var personService = new PersonService( lookupContext );

            var noteTypes = new NoteTypeService( lookupContext ).Queryable().AsNoTracking().ToList();
            var personalNoteType = noteTypes.FirstOrDefault( nt => nt.Guid == new Guid( Rock.SystemGuid.NoteType.PERSON_TIMELINE_NOTE ) );

            var importedUsers = new UserLoginService( lookupContext ).Queryable().AsNoTracking()
                .Where( u => u.ForeignId != null )
                .ToDictionary( t => t.ForeignId, t => t.PersonId );

            var noteList = new List<Note>();

            int completed = 0;
            int totalRows = tableData.Count();
            int percentage = ( totalRows - 1 ) / 100 + 1;
            ReportProgress( 0, string.Format( "Verifying note import ({0:N0} found).", totalRows ) );
            foreach ( var row in tableData.Where( r => r != null ) )
            {
                string text = row["Note_Text"] as string;
                int? individualId = row["Individual_ID"] as int?;
                int? householdId = row["Household_ID"] as int?;
                var noteTypeActive = row["NoteTypeActive"] as Boolean?;

                bool noteArchived = false;
                if ( row.Columns.FirstOrDefault( v => v.Name.Equals( "IsInactive" ) ) != null )
                {
                    /* =====================================================================
                    *  the NoteArchived column *should* work, but OrcaMDF won't read it...
                    *  instead check for a manually added column: IsInactive int null
                    *       var noteActive = row["NoteArchived"] as Boolean?;
                    *       if ( noteActive == null ) throw new NullReferenceException();
                    /* ===================================================================== */
                    var rowInactiveValue = row["IsInactive"] as int?;
                    noteArchived = rowInactiveValue.Equals( 1 );
                }

                var personKeys = GetPersonKeys( individualId, householdId );
                if ( personKeys != null && !string.IsNullOrWhiteSpace( text ) && noteTypeActive == true && !noteArchived )
                {
                    DateTime? dateCreated = row["NoteCreated"] as DateTime?;
                    string noteType = row["Note_Type_Name"] as string;

                    var note = new Note();
                    note.CreatedDateTime = dateCreated;
                    note.EntityId = personKeys.PersonId;

                    // These replace methods don't like being chained together
                    text = Regex.Replace( text, @"\t|\&nbsp;", " " );
                    text = text.Replace( "&#45;", "-" );
                    text = text.Replace( "&lt;", "<" );
                    text = text.Replace( "&gt;", ">" );
                    text = text.Replace( "&amp;", "&" );
                    text = text.Replace( "&quot;", @"""" );
                    text = text.Replace( "&#x0D", string.Empty );

                    note.Text = text.Trim();

                    int? userId = row["NoteCreatedByUserID"] as int?;
                    if ( userId != null && importedUsers.ContainsKey( userId ) )
                    {
                        var userKeys = ImportedPeople.FirstOrDefault( p => p.PersonId == (int)importedUsers[userId] );
                        if ( userKeys != null )
                        {
                            note.CreatedByPersonAliasId = userKeys.PersonAliasId;
                        }
                    }

                    int? matchingNoteTypeId = null;
                    if ( !noteType.StartsWith( "General", StringComparison.InvariantCultureIgnoreCase ) )
                    {
                        matchingNoteTypeId = noteTypes.Where( nt => nt.Name == noteType ).Select( i => (int?)i.Id ).FirstOrDefault();
                    }
                    else
                    {
                        matchingNoteTypeId = personalNoteType.Id;
                    }

                    if ( matchingNoteTypeId != null )
                    {
                        note.NoteTypeId = (int)matchingNoteTypeId;
                    }
                    else
                    {
                        // create the note type
                        var newNoteType = new NoteType();
                        newNoteType.EntityTypeId = personalNoteType.EntityTypeId;
                        newNoteType.EntityTypeQualifierColumn = string.Empty;
                        newNoteType.EntityTypeQualifierValue = string.Empty;
                        newNoteType.UserSelectable = true;
                        newNoteType.IsSystem = false;
                        newNoteType.Name = noteType;
                        newNoteType.Order = 0;

                        lookupContext.NoteTypes.Add( newNoteType );
                        lookupContext.SaveChanges( DisableAuditing );

                        noteTypes.Add( newNoteType );
                        note.NoteTypeId = newNoteType.Id;
                    }

                    noteList.Add( note );
                    completed++;

                    if ( completed % percentage < 1 )
                    {
                        int percentComplete = completed / percentage;
                        ReportProgress( percentComplete, string.Format( "{0:N0} notes imported ({1}% complete).", completed, percentComplete ) );
                    }
                    else if ( completed % ReportingNumber < 1 )
                    {
                        SaveNotes( noteList );
                        ReportPartialProgress();
                        noteList.Clear();
                    }
                }
            }

            if ( noteList.Any() )
            {
                SaveNotes( noteList );
            }

            ReportProgress( 100, string.Format( "Finished note import: {0:N0} notes imported.", completed ) );
        }
        private void GetNoteType()
        {
            string noteTypeName = GetAttributeValue( "NoteType" );

            var service = new NoteTypeService();
            noteType = service.Get( contextEntity.TypeId, noteTypeName );

            // If a note type with the specified name does not exist for the context entity type, create one
            if ( noteType == null )
            {
                noteType = new NoteType();
                noteType.IsSystem = false;
                noteType.EntityTypeId = contextEntity.TypeId;
                noteType.EntityTypeQualifierColumn = string.Empty;
                noteType.EntityTypeQualifierValue = string.Empty;
                noteType.Name = noteTypeName;
                service.Add( noteType, CurrentPersonId );
                service.Save( noteType, CurrentPersonId );
            }
        }
        /// <summary>
        /// Add a note on the given person's record.
        /// </summary>
        /// <param name="personId"></param>
        /// <param name="noteTypeName"></param>
        /// <param name="noteText"></param>
        /// <param name="noteDate">(optional) The date the note was created</param>
        /// <param name="byPersonGuid">(optional) The guid of the person who created the note</param>
        /// <param name="rockContext"></param>
        private void AddNote( int personId, string noteTypeName, string noteText, string noteDate, string byPersonGuid, string isPrivate, RockContext rockContext )
        {
            var service = new NoteTypeService( rockContext );
            var noteType = service.Get( _personEntityTypeId, noteTypeName );
            // if the note type does not exist, create it
            if ( noteType == null )
            {
                noteType = new NoteType();
                noteType.IsSystem = false;
                noteType.EntityTypeId = _personEntityTypeId;
                noteType.EntityTypeQualifierColumn = string.Empty;
                noteType.EntityTypeQualifierValue = string.Empty;
                noteType.Name = noteTypeName;
                service.Add( noteType );
                rockContext.SaveChanges();
            }

            // Find the person's alias
            int? createdByPersonAliasId = null;
            if ( byPersonGuid != null )
            {
                createdByPersonAliasId = _personCache[byPersonGuid.AsGuid()].PrimaryAliasId;
            }

            var noteService = new NoteService( rockContext );
            var note = new Note()
            {
                IsSystem = false,
                NoteTypeId = noteType.Id,
                EntityId = personId,
                Caption = string.Empty,
                CreatedByPersonAliasId = createdByPersonAliasId,
                Text = noteText,
                CreatedDateTime = DateTime.Parse( noteDate ?? RockDateTime.Now.ToString() )
            };

            noteService.Add( note );

            if ( isPrivate.AsBoolean() )
            {
                rockContext.SaveChanges( disablePrePostProcessing: true );
                note.MakePrivate( Rock.Security.Authorization.VIEW, _personCache[byPersonGuid.AsGuid()] );
            }
        }
        /// <summary>
        /// Sets the type of the note.
        /// </summary>
        private void SetNoteType()
        {
            var entityTypeId = EntityTypeCache.Read( typeof( PrayerRequest ) ).Id;
            string noteTypeName = GetAttributeValue( "NoteType" );

            var rockContext = new RockContext();
            var service = new NoteTypeService( rockContext );
            var noteType = service.Get( entityTypeId, noteTypeName );

            // If a note type with the specified name does not exist, create one
            if ( noteType == null )
            {
                noteType = new NoteType();
                noteType.IsSystem = false;
                noteType.EntityTypeId = entityTypeId;
                noteType.EntityTypeQualifierColumn = string.Empty;
                noteType.EntityTypeQualifierValue = string.Empty;
                noteType.Name = noteTypeName;
                service.Add( noteType );
                rockContext.SaveChanges();
            }

            NoteTypeId = noteType.Id;
        }
        /// <summary>
        /// Maps the notes.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        public void MapNotes(IQueryable <Row> tableData)
        {
            var lookupContext   = new RockContext();
            var categoryService = new CategoryService(lookupContext);
            var personService   = new PersonService(lookupContext);

            var noteTypes        = new NoteTypeService(lookupContext).Queryable().AsNoTracking().ToList();
            var personalNoteType = noteTypes.FirstOrDefault(nt => nt.Guid == new Guid(Rock.SystemGuid.NoteType.PERSON_TIMELINE_NOTE));

            var importedUsers = new UserLoginService(lookupContext).Queryable().AsNoTracking()
                                .Where(u => u.ForeignId != null)
                                .ToDictionary(t => t.ForeignId, t => t.PersonId);

            var noteList = new List <Note>();

            int completed  = 0;
            int totalRows  = tableData.Count();
            int percentage = (totalRows - 1) / 100 + 1;

            ReportProgress(0, string.Format("Verifying note import ({0:N0} found).", totalRows));
            foreach (var row in tableData.Where(r => r != null))
            {
                string text           = row["Note_Text"] as string;
                int?   individualId   = row["Individual_ID"] as int?;
                int?   householdId    = row["Household_ID"] as int?;
                var    noteTypeActive = row["NoteTypeActive"] as Boolean?;

                bool noteArchived = false;
                if (row.Columns.FirstOrDefault(v => v.Name.Equals("IsInactive")) != null)
                {
                    /* =====================================================================
                     *  the NoteArchived column *should* work, but OrcaMDF won't read it...
                     *  instead check for a manually added column: IsInactive int null
                     *       var noteActive = row["NoteArchived"] as Boolean?;
                     *       if ( noteActive == null ) throw new NullReferenceException();
                     * /* ===================================================================== */
                    var rowInactiveValue = row["IsInactive"] as int?;
                    noteArchived = rowInactiveValue.Equals(1);
                }

                var personKeys = GetPersonKeys(individualId, householdId);
                if (personKeys != null && !string.IsNullOrWhiteSpace(text) && noteTypeActive == true && !noteArchived)
                {
                    DateTime?dateCreated = row["NoteCreated"] as DateTime?;
                    string   noteType    = row["Note_Type_Name"] as string;

                    var note = new Note();
                    note.CreatedDateTime = dateCreated;
                    note.EntityId        = personKeys.PersonId;

                    // These replace methods don't like being chained together
                    text = Regex.Replace(text, @"\t|\&nbsp;", " ");
                    text = text.Replace("&#45;", "-");
                    text = text.Replace("&lt;", "<");
                    text = text.Replace("&gt;", ">");
                    text = text.Replace("&amp;", "&");
                    text = text.Replace("&quot;", @"""");
                    text = text.Replace("&#x0D", string.Empty);

                    note.Text = text.Trim();

                    int?userId = row["NoteCreatedByUserID"] as int?;
                    if (userId != null && importedUsers.ContainsKey(userId))
                    {
                        var userKeys = ImportedPeople.FirstOrDefault(p => p.PersonId == (int)importedUsers[userId]);
                        if (userKeys != null)
                        {
                            note.CreatedByPersonAliasId = userKeys.PersonAliasId;
                        }
                    }

                    int?matchingNoteTypeId = null;
                    if (!noteType.StartsWith("General", StringComparison.InvariantCultureIgnoreCase))
                    {
                        matchingNoteTypeId = noteTypes.Where(nt => nt.Name == noteType).Select(i => (int?)i.Id).FirstOrDefault();
                    }
                    else
                    {
                        matchingNoteTypeId = personalNoteType.Id;
                    }

                    if (matchingNoteTypeId != null)
                    {
                        note.NoteTypeId = (int)matchingNoteTypeId;
                    }
                    else
                    {
                        // create the note type
                        var newNoteType = new NoteType();
                        newNoteType.EntityTypeId = personalNoteType.EntityTypeId;
                        newNoteType.EntityTypeQualifierColumn = string.Empty;
                        newNoteType.EntityTypeQualifierValue  = string.Empty;
                        newNoteType.UserSelectable            = true;
                        newNoteType.IsSystem = false;
                        newNoteType.Name     = noteType;
                        newNoteType.Order    = 0;

                        lookupContext.NoteTypes.Add(newNoteType);
                        lookupContext.SaveChanges(DisableAuditing);

                        noteTypes.Add(newNoteType);
                        note.NoteTypeId = newNoteType.Id;
                    }

                    noteList.Add(note);
                    completed++;

                    if (completed % percentage < 1)
                    {
                        int percentComplete = completed / percentage;
                        ReportProgress(percentComplete, string.Format("{0:N0} notes imported ({1}% complete).", completed, percentComplete));
                    }
                    else if (completed % ReportingNumber < 1)
                    {
                        SaveNotes(noteList);
                        ReportPartialProgress();
                        noteList.Clear();
                    }
                }
            }

            if (noteList.Any())
            {
                SaveNotes(noteList);
            }

            ReportProgress(100, string.Format("Finished note import: {0:N0} notes imported.", completed));
        }
Example #12
0
        /// <summary>
        /// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick( object sender, EventArgs e )
        {
            int noteTypeId = 0;
            if ( hfIdValue.Value != string.Empty && !int.TryParse( hfIdValue.Value, out noteTypeId ) )
            {
                noteTypeId = 0;
            }

            var rockContext = new RockContext();
            var service = new NoteTypeService( rockContext );
            NoteType noteType = null;

            if ( noteTypeId != 0 )
            {
                noteType = service.Get( noteTypeId );
            }

            if ( noteType == null )
            {
                var orders = service.Queryable()
                    .Where( t => t.EntityTypeId == ( entityTypePicker.SelectedEntityTypeId ?? 0 ) )
                    .Select( t => t.Order )
                    .ToList();

                noteType = new NoteType();
                noteType.Order = orders.Any() ? orders.Max( t => t ) + 1 : 0;
                service.Add( noteType );
            }

            noteType.Name = tbName.Text;
            noteType.EntityTypeId = entityTypePicker.SelectedEntityTypeId ?? 0;
            noteType.EntityTypeQualifierColumn = "";
            noteType.EntityTypeQualifierValue = "";
            noteType.UserSelectable = cbUserSelectable.Checked;
            noteType.CssClass = tbCssClass.Text;
            noteType.IconCssClass = tbIconCssClass.Text;

            if ( noteType.IsValid )
            {
                rockContext.SaveChanges();

                NoteTypeCache.Flush( noteType.Id );
                NoteTypeCache.FlushEntityNoteTypes();

                hfIdValue.Value = string.Empty;
                modalDetails.Hide();

                BindFilter();
                BindGrid();
            }
        }