public List <EasyTree> getTree(int pid) { List <EasyTree> modelList = new List <EasyTree>(); var list = treebll.GetList(pid); if (list.Count > 0) { foreach (var item in list) { EasyTree model = new EasyTree(); model.children = new List <EasyTree>(); model.id = item.id; model.text = item.text; model.state = "closed"; model.ischecked = true; model.attributes = item.attributes; var sonTree = getTree(item.id); if (sonTree != null) { model.children.AddRange(sonTree); } modelList.Add(model); } } return(modelList); }
public JsonResult GetTree() { List <EasyTree> list = treebll.GetList(0); List <EasyTree> trees = new List <EasyTree>(); if (list != null && list.Count > 0) { foreach (var item in list) { EasyTree TreeModel = new EasyTree(); TreeModel.children = new List <EasyTree>(); TreeModel.id = item.id; TreeModel.attributes = item.attributes; TreeModel.text = item.text; TreeModel.state = "open"; TreeModel.ischecked = true; var treeson = getTree(item.id); if (treeson != null && treeson.Count > 0) { TreeModel.children.AddRange(treeson); } trees.Add(TreeModel); } } var json = trees.ToArray(); return(Json(json, JsonRequestBehavior.AllowGet)); }
public int Create(EasyTree entity) { using (TreeContext db = new TreeContext()) { db.Set <EasyTree>().Add(entity); return(db.SaveChanges()); } }
public int Edit(EasyTree entity) { using (TreeContext db = new TreeContext()) { db.Set <EasyTree>().Attach(entity); db.Entry <EasyTree>(entity).State = EntityState.Modified; return(db.SaveChanges()); } }
public int Delete(int id) { using (TreeContext db = new TreeContext()) { EasyTree entity = db.EasyTrees.SingleOrDefault(a => a.id == id); db.Set <EasyTree>().Remove(entity); int row = db.SaveChanges(); return(row > 0 ? 1 : 0); } }
public bool IsExist(int id) { using (TreeContext db = new TreeContext()) { EasyTree entity = GetById(id); if (entity != null) { return(true); } return(false); } }
public EasyTree GetById(int id) { if (IsExist(id)) { EasyTree entity = Rep.GetById(id); return(entity); } else { return(null); } }
public bool Edit(EasyTree entity) { try { if (Rep.Edit(entity) == 1) { return(true); } else { return(false); } } catch (Exception) { //ExceptionHander.WriteException(ex); return(false); } }