public void CreateSubject(Subject s) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository<Subject>(); rep.Insert(s); } }
public void CreateSubject(Subject s, string theSubjectTitle) { if (s == null || s.SubjectId != 0 || s.SubjectOrder == 0) throw new Exception("Cannot create subject"); }
public void DeleteSubject(Subject s) { using (IDataContext db = DataContext.Instance()) { var rep = db.GetRepository<Subject>(); rep.Delete(s); } }
public void CreateSubject(Subject s, int userId) { if (s == null || s.SubjectId != 0 || s.SubjectOrder == 0) throw new Exception("Cannot create subject"); IEnumerable<Subject> sameMother = rep.GetChildrenSubjects(s.MotherId); foreach(Subject tmpS in sameMother) { if (tmpS.SubjectOrder >= s.SubjectOrder) { tmpS.SubjectOrder++; rep.UpdateSubject(tmpS); } } rep.CreateSubject(s); PHText sText = new PHText(s.label, "en-US", ETextItemType.Subject); sText.CreatedByUserId = userId; sText.ItemId = s.SubjectId; sText.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage; SavePhTextInAllCc(sText); }
public void DeleteSubject(Subject s) { if (s == null || s.SubjectId == 0) throw new Exception("Cannot delete subject"); PHText sText = GetCurrentVersionText("en-US", s.SubjectId, ETextItemType.Subject); rep.DeletePhText(sText); IEnumerable<Subject> sameMother = rep.GetChildrenSubjects(s.MotherId); foreach(Subject tmpS in sameMother) { if (tmpS.SubjectOrder > s.SubjectOrder) { tmpS.SubjectOrder--; rep.UpdateSubject(tmpS); } } rep.DeleteSubject(s); }
/// <summary> /// Returns the root subject. The root subject has SubjectId = 0. It has all first level subjects as children. /// Navigate up and down hierarchy using children[] and Mother. /// </summary> /// <param name="cultureCode"></param> /// <param name="list"></param> /// <returns></returns> public Subject RootSubject(string cultureCode, IEnumerable<Subject> list = null) { if (list == null) list = GetSubjectsAsFlatList(cultureCode); Subject root = new Subject(); root.children = new List<Subject>(); Dictionary<int, Subject> dict = new Dictionary<int, Subject>(); foreach (Subject s in list) { dict.Add(s.SubjectId, s); s.children = new List<Subject>(); } foreach (Subject e in list) { if(e.MotherId==0) { root.children.Add(e); e.Mother = root; } else { dict[e.MotherId].children.Add(e); e.Mother = dict[e.MotherId]; } } return root; }
private void CreateSubject(int order, int motherId) { BaseHandler bh = new BaseHandler(); Subject newSubject = new Subject(); newSubject.label = txtAddSubject.Text; newSubject.SubjectOrder = order; newSubject.MotherId = motherId; bh.CreateSubject(newSubject, this.UserId); txtAddSubject.Text = ""; BindTree(); }
/// <summary> /// Retrieve next subject in hierarchy (Think of an expanded subject tree. Will get the "next row") /// </summary> /// <param name="s"></param> /// <returns></returns> public Subject NextSubject(Subject s) { bool SearchChildren = true; while(1==1) { if (s.SubjectId == 0) return null; if (SearchChildren && s.children.Count > 0) return s.children[0]; if (s.Mother.children.Count > s.SubjectOrder) return s.Mother.children[s.SubjectOrder]; s = s.Mother; SearchChildren = false; } }
public void HierarchyToFlat(Subject s, List<Subject> flatList) { flatList.Add(s); foreach(Subject child in s.children) { HierarchyToFlat(child, flatList); } }
/// <summary> /// Returns the subject in the form "Natural Science -> Physics -> Quantum Mechanics" /// </summary> /// <param name="cultureCode"></param> /// <param name="subjectId"></param> /// <param name="root"></param> /// <returns></returns> public string GetSubjectString(string cultureCode, int subjectId, Subject root = null) { if (root == null) root = RootSubject(cultureCode); Subject s = FindSubject(cultureCode, subjectId, root); StringBuilder theS = new StringBuilder(s.label); if (s == null) return null; while (s.MotherId != 0) { s = s.Mother; theS.Insert(0, s.label + " <span class=\"glyphicons glyph-right-arrow\"></span> "); } return theS.ToString(); }
/// <summary> /// Converts a flat list of all Subjects into a hierarchy. /// Will set Mother as well as Children /// </summary> /// <param name="list">Get list from GetSubjectsAsFlatList</param> /// <param name="motherId">Do not use this parameter</param> /// <returns></returns> public List<Subject> FlatToHierarchy(IEnumerable<Subject> list, int motherId = 0, Subject mother = null) { return (from i in list where i.MotherId == motherId select new Subject { SubjectId = i.SubjectId, SubjectOrder = i.SubjectOrder, MotherId = i.MotherId, label = i.label, Mother = mother, children = FlatToHierarchy(list, i.SubjectId, i) }).ToList(); }
/// <summary> /// Find a specific subject in the hierarchy. Navigate up and down hierarchy using children[] and Mother. /// </summary> /// <param name="cultureCode"></param> /// <param name="subjectId"></param> /// <param name="root"></param> /// <returns></returns> public Subject FindSubject(string cultureCode, int subjectId, Subject root = null) { if (root == null) root = RootSubject(cultureCode); foreach (Subject s in root.children) { if (s.SubjectId == subjectId) return s; if (s.children.Count > 0) { Subject fs = FindSubject(cultureCode, subjectId, s); if (fs != null) return fs; } } return null; }