/// <summary> /// 保存权限 /// </summary> /// <param name="role"></param> /// <param name="allResource"></param> /// <param name="resource"></param> /// <param name="pmsExp"></param> /// <param name="deleteResList"></param> /// <param name="deleteRoleList"></param> /// <returns></returns> public static int SavePermission(Role role, List <Priv> allResource, List <Priv> resource, string pmsExp, List <Priv> deleteResList, List <Role> deleteRoleList) { //using (DaoManager daoMgr = new DaoManager()) //{ try { //daoMgr.BeginTransaction(); PrivLogic privlogic = new PrivLogic(); foreach (Priv res in allResource) { privlogic.DelResRoleMap(res.Id, role.ID); } //级联删除所有子角色对应的资源 foreach (Role childrole in deleteRoleList) { foreach (Priv delRes in deleteResList) { privlogic.DelResRoleMap(delRes.Id, childrole.ID); } } foreach (Priv newRes in resource) { privlogic.InsertResRoleMap(newRes, role.ID, pmsExp, ""); } //daoMgr.CommitTransaction(); return(1); } catch (Exception ex) { //daoMgr.RollBackTransaction(); throw ex; } //} }
/// <summary> /// 撤销角色权限 /// </summary> public int Revoke(Role role, Priv resource, IList <Operation> operations) { // using (DaoManager _dao = new DaoManager()) // { PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); string _pmsExp = ""; if (_permission != null && _permission.Count > 0) //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { if (!IsContainOperation(_opera, operations)) { _pmsExp = _pmsExp + _opera.Id + "|"; } } break; } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, "")); } return(0); //} }
/// <summary> /// 角色授权 /// </summary> public int Grant(Role role, Priv resource, IList <Operation> operations, object param) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); string _pmsExp = ""; //新增 if (_permission.Count == 0) { foreach (Operation _opera in operations) { _pmsExp = _pmsExp + _opera.Id + "|"; } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, (param == null ? "" : param.ToString()))); } else //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { _pmsExp = _pmsExp + _opera.Id + "|"; } break; } foreach (Operation _opera in operations) { if (_pmsExp.IndexOf(_opera.Id) < 0) { _pmsExp = _pmsExp + _opera.Id + "|"; } } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, (param == null ? "" : param.ToString()))); } //} }
/// <summary> /// 保存权限 /// </summary> /// <param name="resType"></param> /// <param name="role"></param> /// <param name="resource"></param> /// <param name="pmsExp"></param> /// <returns></returns> public static int SavePermission(string resType, Role role, Priv resource, string pmsExp) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resType, resource.Id, role); //新增 if (_permission.Count > 0) { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } } return(privlogic.InsertResRoleMap(resource, role.ID, pmsExp, "")); //} }