public ApiResult AddMenu([FromBody] MenuAdd model) { result = AccessToken.Check(model.access_token, "api/role/addmenu"); if (result == null) { #region 参数验证 result = ParameterCheck.CheckParameters(model); if (result != null) { return(result); } #endregion #region 逻辑操作 var menulist = from T_Right in db.T_Right where (T_Right.Url == model.Url) select T_Right; if (menulist.Any()) { //已存在 return(Error("此API功能接口已存在")); } else { T_Right rightModel = new T_Right(); rightModel.ID = System.Guid.NewGuid().ToString(); rightModel.Name = model.Name; rightModel.Url = model.Url; rightModel.Priority = 1; try { db.T_Right.Add(rightModel); db.SaveChanges(); return(Success("添加成功")); } catch { return(Error("添加失败")); } } #endregion } return(result); }
public ApiResult ModifyMenu([FromBody] MenuModify model) { result = AccessToken.Check(model.access_token, "api/role/modmenu"); if (result == null) { #region 参数验证 result = ParameterCheck.CheckParameters(model); if (result != null) { return(result); } #endregion #region 逻辑操作 T_Right rightModel = db.T_Right.Find(model.ID); if (rightModel != null) { if (rightModel.Priority == 0) { return(Error("此记录不能被修改")); } rightModel.Name = model.Name; rightModel.Url = model.Url; try { db.SaveChanges(); return(Success("修改成功")); } catch { return(Error("修改失败")); } } else { return(Error("未找到此记录")); } #endregion } return(result); }
public ApiResult DeleteMenu(string access_token, string ID) { result = AccessToken.Check(access_token, "api/role/delmenu"); if (result == null) { #region 参数验证 if (ID == null || ID == "") { return(Error("参数错误,ID不能为空")); } #endregion #region 逻辑操作 T_Right rightModel = db.T_Right.Find(ID); if (rightModel != null) { var rightMenuList = from vw_Role in db.vw_Role where (vw_Role.MenuID == ID) select vw_Role; if (rightMenuList.Any()) { return(Error("此接口已被使用,不能被删除")); } try { db.T_Right.Remove(rightModel); db.SaveChanges(); return(Success("删除成功")); } catch { return(Error("删除失败")); } } else { return(Error("未找到此记录")); } #endregion } return(result); }