public static bool SysConfig(this User user, bool enable) { user.LoadRole(); var ur = user.UserRole; SystemRole sr = (SystemRole)ur.SystemRole; var flag = sr.HasFlag(SystemRole.SysConfig); if (enable) { if (flag) { return true; } else { sr = sr | SystemRole.SysConfig; } } else { if (flag) { sr = (SystemRole)(sr - SystemRole.SysConfig); } else { return true; } } using (var cxt = new OASysModelContainer()) { user.LoadRole(); cxt.UserRole.Attach(ur); ur.SystemRole = (int)sr; return cxt.SaveChanges() > 0; } }
public ActionResult PermEdit([Bind(Exclude = "SystemRole,DesktopRole")]Perm perm) { ActionResult ar; User user; if (!UserVal(out ar,out user)) { return ar; } var permFlag = user.HasPermManage(); if (!permFlag) { return Content("修改失败,权限不足"); } if (perm.SystemRole == -1 || perm.DesktopRole == -1) { return Content("修改失败,检测到非法提交"); } bool flag; using (var cxt = new OASysModelContainer()) { var role = cxt.UserRole.SingleOrDefault(r => r.RoleId == perm.RoleId); role.SystemRole = perm.SystemRole; role.DesktopRole = perm.DesktopRole; flag = cxt.SaveChanges() > 0; } if (flag) { return Content("修改成功"); } else { return Content("修改失败"); } }