Example #1
0
        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);
        }
Example #2
0
        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));
        }
Example #3
0
 public int Create(EasyTree entity)
 {
     using (TreeContext db = new TreeContext())
     {
         db.Set <EasyTree>().Add(entity);
         return(db.SaveChanges());
     }
 }
Example #4
0
 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());
     }
 }
Example #5
0
        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);
            }
        }
Example #6
0
 public bool IsExist(int id)
 {
     using (TreeContext db = new TreeContext())
     {
         EasyTree entity = GetById(id);
         if (entity != null)
         {
             return(true);
         }
         return(false);
     }
 }
Example #7
0
        public EasyTree GetById(int id)
        {
            if (IsExist(id))
            {
                EasyTree entity = Rep.GetById(id);


                return(entity);
            }
            else
            {
                return(null);
            }
        }
Example #8
0
 public bool Edit(EasyTree entity)
 {
     try
     {
         if (Rep.Edit(entity) == 1)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         //ExceptionHander.WriteException(ex);
         return(false);
     }
 }