/// <summary> /// 权限模块关系表 列表 /// </summary> public ActionResult role_moduleList(tb_role_module model) { int count = 0; ViewBag.role_moduleList = drole_module.GetList(model, ref count); ViewBag.page = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5); return(View()); }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_role_module GetInfo(tb_role_module model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from tb_role_module"); strSql.Append(" where roleid=@roleid and moduleid=@moduleid "); using (IDbConnection conn = DapperHelper.OpenConnection()) { model = conn.Query <tb_role_module>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 权限模块关系表 保存 /// </summary> public JsonResult role_moduleSave(tb_role_module model) { if (model == null) { return(ResultTool.jsonResult(false, "参数错误!")); } if (!String.IsNullOrEmpty(model.roleid)) { bool boolResult = drole_module.Update(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "更新失败!")); } else { model.roleid = Guid.NewGuid().ToString("N"); bool boolResult = drole_module.Add(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "添加失败!")); } }
/// <summary> /// 删除一条数据 /// </summary> public bool Delete(tb_role_module model) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from tb_role_module "); strSql.Append(" where roleid=@roleid and moduleid=@moduleid "); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 获得数据列表 /// </summary> public List <tb_role_module> GetList(tb_role_module model, ref int total) { List <tb_role_module> list; StringBuilder strSql = new StringBuilder(); StringBuilder whereSql = new StringBuilder(" where 1 = 1 "); strSql.Append(" select ROW_NUMBER() OVER(ORDER BY roleid desc) AS RID, * from tb_role_module "); strSql.Append(whereSql); string CountSql = "SELECT COUNT(1) as RowsCount FROM (" + strSql.ToString() + ") AS CountList"; string pageSqlStr = "select * from ( " + strSql.ToString() + " ) as Temp_PageData where Temp_PageData.RID BETWEEN {0} AND {1}"; pageSqlStr = string.Format(pageSqlStr, (model.PageSize * (model.PageIndex - 1) + 1).ToString(), (model.PageSize * model.PageIndex).ToString()); using (IDbConnection conn = DapperHelper.OpenConnection()) { list = conn.Query <tb_role_module>(pageSqlStr, model)?.ToList(); total = conn.ExecuteScalar <int>(CountSql, model); } return(list); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_role_module model) { StringBuilder strSql = new StringBuilder(); StringBuilder setSql = new StringBuilder(); strSql.Append("update tb_role_module set "); strSql.Append(setSql.ToString().TrimEnd(',')); strSql.Append(" where roleid=@roleid and moduleid=@moduleid "); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(tb_role_module model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_role_module("); strSql.Append("roleid,moduleid)"); strSql.Append(" values ("); strSql.Append("@roleid,@moduleid)"); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 权限模块关系表 详情 /// </summary> public ActionResult role_moduleInfo(tb_role_module model) { model = drole_module.GetInfo(model); return(View(model ?? new tb_role_module())); }
/// <summary> /// 权限模块关系表 删除 /// </summary> public JsonResult role_moduleDelete(tb_role_module model) { bool boolResult = drole_module.Delete(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "删除失败!")); }