public ResultModel Create(UserModel user, int empId, List<Model.AuthOperate> authOperates, List<Model.EmpMenu> empMenus, string exceptItemIds) { ResultModel result = new ResultModel(); DAL.MenuDAL menuDAL = new MenuDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //if (authOperates == null || !authOperates.Any()) //{ // result.ResultStatus = -1; // result.Message = "数据错误"; // return result; //} DAL.AuthOperateDAL authOperateDAL = new AuthOperateDAL(); result = authOperateDAL.InvalidAll(user, empId, exceptItemIds); if (result.ResultStatus != 0) return result; if (authOperates != null || authOperates.Any()) { foreach (Model.AuthOperate authOperate in authOperates) { result = authoperateDAL.Insert(user, authOperate); if (result.ResultStatus != 0) return result; } } if (empMenus != null && empMenus.Any()) { DAL.EmpMenuDAL empMenuDAL = new EmpMenuDAL(); //result = empMenuDAL.InvalidAll(user, empId); //if (result.ResultStatus != 0) // return result; foreach (Model.EmpMenu empMenu in empMenus) { result = empMenuDAL.Insert(user, empMenu); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
public ResultModel GetMenuList(UserModel user, int empId, string menuIds) { ResultModel result = new ResultModel(); try { //获取操作权限列表 DAL.MenuDAL menuDAL = new MenuDAL(); result = menuDAL.GetOperateMenu(user); if (result.ResultStatus != 0) return result; DataTable dtOperate = result.ReturnValue as DataTable; if (dtOperate == null || dtOperate.Rows.Count < 1) { result.ResultStatus = -1; result.Message = "获取失败"; return result; } //获取用户操作权限 result = authoperateDAL.GetOperate(user, empId); if (result.ResultStatus != 0) return result; DataTable dtEmpAuth = result.ReturnValue as DataTable; result = authoperateDAL.GetMenuList(user, empId, menuIds); if (result.ResultStatus != 0) return result; DataTable dt = result.ReturnValue as DataTable; if (dt != null && dt.Rows.Count > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("["); foreach (DataRow dr in dt.AsEnumerable().Where(row => Convert.ToInt32(row["ParentId"]) == 0)) { sb.Append("{"); //一级菜单 sb.AppendFormat("\"label\":\"{0}\",\"id\":\"{1}\",\"checked\":{2}", dr["label"].ToString(), Convert.ToInt32(dr["id"]).ToString(), Convert.ToBoolean(dr["checked"]).ToString().ToLower()); if (dt.AsEnumerable().Any(row => Convert.ToInt32(row["ParentId"]) == Convert.ToInt32(dr["id"]))) { var items = dt.AsEnumerable().Where(detail => Convert.ToInt32(detail["ParentId"]) == Convert.ToInt32(dr["id"])); sb.Append(",\"items\":["); foreach (DataRow drDetail in items) { sb.Append("{"); //二级菜单 sb.AppendFormat("\"label\":\"{0}\",\"id\":\"{1}\",\"checked\":{2}", drDetail["label"].ToString(), drDetail["id"].ToString(), drDetail["checked"].ToString().ToLower()); sb.Append(",\"items\":["); bool hasAuth = dtEmpAuth.AsEnumerable().Any(temp => Convert.ToInt32(temp["MenuId"]) == Convert.ToInt32(drDetail["id"])); foreach (DataRow drOp in dtOperate.Rows) { sb.Append("{"); //菜单操作权限 sb.AppendFormat("\"label\":\"{0}\",\"id\":\"{1}\",\"checked\":{2},\"html\":\"{3}\"", drOp["DetailName"].ToString(), "op_" + drDetail["id"].ToString() + "_" + drOp["StyleDetailId"].ToString(), hasAuth ? dtEmpAuth.AsEnumerable().Any(row => Convert.ToInt32(row["OperateType"]) == Convert.ToInt32(drOp["StyleDetailId"]) && Convert.ToInt32(row["MenuId"]) == Convert.ToInt32(drDetail["id"])).ToString().ToLower() : "false", "style='float:left;'"); sb.Append("},"); } sb = sb.Remove(sb.Length - 1, 1); sb.Append("]},"); } sb = sb.Remove(sb.Length - 1, 1); sb.Append("]"); } else { sb.Append(",\"items\":["); bool hasAuth = dtEmpAuth.AsEnumerable().Any(temp => Convert.ToInt32(temp["MenuId"]) == Convert.ToInt32(dr["id"])); foreach (DataRow drOp in dtOperate.Rows) { sb.Append("{"); //菜单操作权限 sb.AppendFormat("\"label\":\"{0}\",\"id\":\"{1}\",\"checked\":{2},\"html\":\"{3}\"", drOp["DetailName"].ToString(), "op_" + dr["id"].ToString() + "_" + drOp["StyleDetailId"].ToString(), hasAuth ? dtEmpAuth.AsEnumerable().Any(row => Convert.ToInt32(row["OperateType"]) == Convert.ToInt32(drOp["StyleDetailId"]) && Convert.ToInt32(row["MenuId"]) == Convert.ToInt32(dr["id"])).ToString().ToLower() : "false", "style='float:left;'"); sb.Append("},"); } sb = sb.Remove(sb.Length - 1, 1); sb.Append("]"); } sb.Append("},"); } sb = sb.Remove(sb.Length - 1, 1); sb.Append("]"); result.ResultStatus = 0; result.Message = "操作成功"; result.ReturnValue = sb.ToString(); } else { result.ResultStatus = -1; result.Message = "操作失败"; } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }