public string Delete(int ID) { RedBloodDataContext db = new RedBloodDataContext(); TestDef c = (from i in db.TestDefs where i.ID == ID select i).First(); if (c == null) { return(""); } Delete_Route(c, db); try { db.SubmitChanges(); return(""); } catch (Exception) { return("Dữ liệu đã được sử dụng. Không thể xóa."); } }
public void Delete_Route(TestDef c, RedBloodDataContext db) { foreach (TestDef e in c.Children) { Delete_Route(e, db); } db.TestDefs.DeleteOnSubmit(c); }
public void Update(int ID, string name) { RedBloodDataContext db = new RedBloodDataContext(); TestDef c = (from i in db.TestDefs where i.ID == ID select i).First(); if (c == null) { return; } c.Name = name; db.SubmitChanges(); }
//public static TestDef GetConst(int ID) //{ // return TestDef.all.Where(r => r.ID == ID).FirstOrDefault(); //} public string Insert(string name, int level, int?parentID) { RedBloodDataContext db = new RedBloodDataContext(); TestDef e = new TestDef(); e.Name = name.Trim(); e.Level = level; e.ParentID = parentID; db.TestDefs.InsertOnSubmit(e); try { db.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } return(""); }
partial void DeleteTestDef(TestDef instance);
partial void UpdateTestDef(TestDef instance);
partial void InsertTestDef(TestDef instance);
private void detach_Children(TestDef entity) { this.SendPropertyChanging(); entity.Parent = null; }
//public static TestDef GetConst(int ID) //{ // return TestDef.all.Where(r => r.ID == ID).FirstOrDefault(); //} public string Insert(string name, int level, int? parentID) { RedBloodDataContext db = new RedBloodDataContext(); TestDef e = new TestDef(); e.Name = name.Trim(); e.Level = level; e.ParentID = parentID; db.TestDefs.InsertOnSubmit(e); try { db.SubmitChanges(); } catch (Exception ex) { return ex.Message; } return ""; }