Beispiel #1
0
        private void BindGrid()
        {
            gList.Visible = true;
            RockContext         rockContext         = new RockContext();
            NoteTemplateService noteTemplateService = new NoteTemplateService(rockContext);
            var qry = noteTemplateService.Queryable().AsNoTracking().OrderBy(nt => nt.Order);

            var list = qry.ToList();

            gList.DataSource = list;
            gList.DataBind();
        }
Beispiel #2
0
        /// <summary>
        /// Handles the GridReorder event of the gList control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gList_GridReorder(object sender, GridReorderEventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                NoteTemplateService noteTemplateService = new NoteTemplateService(rockContext);
                var noteTemplates = noteTemplateService.Queryable().OrderBy(nt => nt.Order).ToList();
                noteTemplateService.Reorder(noteTemplates, e.OldIndex, e.NewIndex);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Beispiel #3
0
        /// <summary>
        /// Adds the New Worker
        /// </summary>
        private bool AddNote(int noteTemplateId)
        {
            if (Page.IsValid)
            {
                RockContext         rockContext         = new RockContext();
                NoteTemplateService noteTemplateService = new NoteTemplateService(rockContext);

                NoteTemplate noteTemplate = null;

                if (!noteTemplateId.Equals(0))
                {
                    noteTemplate = noteTemplateService.Get(noteTemplateId);
                }

                if (noteTemplate == null)
                {
                    noteTemplate = new NoteTemplate {
                        Id = 0
                    };
                }

                noteTemplate.Icon = tbIcon.Text;

                noteTemplate.Note = tbNote.Text;

                noteTemplate.IsActive = cbActive.Checked;

                NoteTemplate lastNoteTemplate = noteTemplateService.Queryable().OrderByDescending(b => b.Order).FirstOrDefault();

                if (lastNoteTemplate != null)
                {
                    noteTemplate.Order = lastNoteTemplate.Order + 1;
                }
                else
                {
                    noteTemplate.Order = 0;
                }

                if (noteTemplate.IsValid)
                {
                    if (noteTemplate.Id.Equals(0))
                    {
                        noteTemplateService.Add(noteTemplate);
                    }

                    // get attributes
                    noteTemplate.LoadAttributes();
                    Helper.GetEditValues(phAttributes, noteTemplate);

                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.SaveChanges();
                        noteTemplate.SaveAttributeValues(rockContext);
                    });

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }