/// <summary> /// Shows the detail. /// </summary> /// <param name="noteTemplateId">The care worker identifier</param> public void ShowDetail(int noteTemplateId) { NoteTemplate noteTemplate = null; var rockContext = new RockContext(); NoteTemplateService noteTemplateService = new NoteTemplateService(rockContext); if (!noteTemplateId.Equals(0)) { noteTemplate = noteTemplateService.Get(noteTemplateId); pdAuditDetails.SetEntity(noteTemplate, ResolveRockUrl("~")); } if (noteTemplate == null) { noteTemplate = new NoteTemplate { Id = 0 }; pdAuditDetails.Visible = false; cbActive.Checked = true; } else { cbActive.Checked = noteTemplate.IsActive; } tbIcon.Text = noteTemplate.Icon; tbNote.Text = noteTemplate.Note; noteTemplate.LoadAttributes(); Helper.AddEditControls(noteTemplate, phAttributes, true, BlockValidationGroup, 2); hfNoteTemplateId.Value = noteTemplate.Id.ToString(); }
/// <summary> /// Handles the Delete event of the gList 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 gList_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); NoteTemplateService service = new NoteTemplateService(rockContext); NoteTemplate noteTemplate = service.Get(e.RowKeyId); if (noteTemplate != null) { service.Delete(noteTemplate); rockContext.SaveChanges(); } BindGrid(); }
/// <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); } }