/// <summary> /// 编辑树的节点 /// </summary> /// <param name="condtion"></param> /// <returns></returns> public BaseTree EditBaseTree(BaseTreeAttr condtion) { ValiDatas.valiData(condtion); var r = CheckCode(condtion.Code, this.id); if (r > 0) { throw new ValiDataException(string.Format("code [{0}] 已存在,保存失败", condtion.Code)); } using (var db = new DefaultContainer()) { var row = db.Db_BaseTreeSet.Single(p => p.Id == this.id); row.Code = condtion.Code; row.Name = condtion.text; row.ParentId = string.IsNullOrEmpty(condtion.ParentId) ? null : condtion.ParentId; row.Seq = condtion.Seq; db.SaveChanges(); return(BaseTree.GetBaseTreeById(this.id)); } }
/// <summary> /// 新增树的节点 /// </summary> /// <param name="condtion"></param> /// <returns></returns> public static BaseTree CreateBaseTree(BaseTreeAttr condtion) { ValiDatas.valiData(condtion); var r = CheckCode(condtion.Code); if (r > 0) { throw new ValiDataException(string.Format("code [{0}] 已存在,新增失败", condtion.Code)); } using (var db = new DefaultContainer()) { Db_BaseTree dbTree = new Db_BaseTree() { Id = Guid.NewGuid().ToString(), Code = condtion.Code, CreatedOn = DateTime.Now, Name = condtion.text, ParentId = string.IsNullOrEmpty(condtion.ParentId)? null :condtion.ParentId, Seq = condtion.Seq }; db.Db_BaseTreeSet.Add(dbTree); db.SaveChanges(); return(new BaseTree(dbTree)); } }