public void CreateSubject(SubjectEntity s) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository<SubjectEntity>(); rep.Insert(s); } }
public void DeleteSubject(SubjectEntity s) { using (IDataContext db = DataContext.Instance()) { var rep = db.GetRepository<SubjectEntity>(); rep.Delete(s); } }
/// <summary> /// Add a new Subject to DB /// </summary> /// <param name="s"></param> /// <param name="userId"></param> public void CreateSubject(Subject s, int userId) { if (s == null || s.SubjectId != 0 || s.SubjectOrder == 0) throw new Exception("Cannot create subject"); IEnumerable<SubjectEntity> sameMother = rep.GetChildrenSubjects(s.MotherId); foreach (SubjectEntity tmpS in sameMother) { if (tmpS.SubjectOrder >= s.SubjectOrder) { tmpS.SubjectOrder++; rep.UpdateSubject(tmpS); } } SubjectEntity se = new SubjectEntity { SubjectOrder = s.SubjectOrder, MotherId = s.MotherId }; rep.CreateSubject(se); PHText sText = new PHText(s.label, "en-US", ETextItemType.Subject); sText.CreatedByUserId = userId; sText.ItemId = se.SubjectId; sText.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage; SavePhTextInAllCc(sText); }