Beispiel #1
0
        /// <summary>
        /// Handles the Delete event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void rGrid_Delete(object sender, RowEventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var service  = new NoteTypeService(rockContext);
                var noteType = service.Get(e.RowKeyId);
                if (noteType != null)
                {
                    string errorMessage = string.Empty;
                    if (service.CanDelete(noteType, out errorMessage))
                    {
                        int id = noteType.Id;

                        service.Delete(noteType);
                        rockContext.SaveChanges();

                        NoteTypeCache.Flush(id);
                        NoteTypeCache.FlushEntityNoteTypes();
                    }
                    else
                    {
                        nbMessage.Text    = errorMessage;
                        nbMessage.Visible = true;
                    }
                }
            }

            BindFilter();
            BindGrid();
        }
Beispiel #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();
            }
        }