public int AddTreeNode(int id) { //api/SysRole/AddTreeNode/0 TbSysRole tmpNode = new TbSysRole(); tmpNode.IParentId = id;//此处的id为parentid tmpNode.SRoleName = "新增结点"; if (id != 0) { //非一级节点,先读取父结点 TbSysRole parentNode = SysRoleDAO.GetByID(id); if (parentNode != null) { tmpNode.ILevel = parentNode.ILevel + 1; } else { return -1; //Request.CreateResponse(HttpStatusCode.BadRequest, "出错了,找不到新建 SysRole 的 父结点:"+id+"!!"); } } else { //一级节点 tmpNode.ILevel = 1; } SysRoleDAO.Insert(tmpNode); int tempId = tmpNode.Id;//新增节点的ID return tempId; }
/// <summary> /// 通过对象删除记录 /// </summary> /// <param name="item"></param> /// <returns></returns> public bool Del( TbSysRole item) { bool res = false; using (var connection = DataBase.GetOpenConnection()) { res = connection.Delete< TbSysRole>(item); } return res; }
/// <summary> /// 通过ID删除记录 /// </summary> /// <param name="id">需要删除的对象的ID</param> /// <returns></returns> public bool Del(int id) { bool res = false; TbSysRole item = new TbSysRole(); using (var connection = DataBase.GetOpenConnection()) { item = GetByID(id); res = connection.Delete<TbSysRole>(item); } return res; }
/// <summary> /// PUT api/SysRole/Put/5,更新数据 /// </summary> public int Put(int id, TbSysRole item) { if (id != item.Id) { //数据无效 return -1; } try { SysRoleDAO.Update(item); } catch (Exception ex) { //更新数据失败 return -2; } //更新成功 return 1; }
/// <summary> /// POST api/SysRole/Post ///新增item数据, /// </summary> /// <param name="item">item,新增数据</param> public int Post(TbSysRole item) { if (ModelState.IsValid) { SysRoleDAO.Insert(item); return 1;//新增数据成功 } else { //数据验证失败 return 0; } }
/// <summary> /// 插入一个对象 /// </summary> /// <param name="item">需要插入的对象</param> /// <returns></returns> public int Insert(TbSysRole item) { int id = 0; using (var connection = DataBase.GetOpenConnection()) { id = (int)connection.Insert<TbSysRole>(item); } return id; }