/// <summary> /// 授予用户操作权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键数组</param> /// <param name="grantPermissionIds">授予权限数组</param> /// <returns>影响的行数</returns> public int GrantUserPermissions(BaseUserInfo userInfo, string[] userIds, string[] grantPermissionIds) { int result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var manager = new BaseUserPermissionManager(dbHelper, userInfo); // 小心异常,检查一下参数的有效性 if (userIds != null && grantPermissionIds != null) { result += manager.Grant(userInfo.SystemCode, userIds, grantPermissionIds); } }); return(result); }
/// <summary> /// 授予用户操作权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <param name="grantPermissionIds">授予权限数组</param> /// <returns>影响的行数</returns> public string GrantUserPermissionById(BaseUserInfo userInfo, string userId, string grantPermissionId) { string result = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var manager = new BaseUserPermissionManager(dbHelper, userInfo); // 小心异常,检查一下参数的有效性 if (grantPermissionId != null) { result = manager.Grant(userInfo.SystemCode, userId, grantPermissionId); } }); return(result); }
/// <summary> /// 给用户权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userName">用户名</param> /// <param name="permissionItemCode">权限编号</param> /// <returns>主键</returns> public string GrantUserPermission(BaseUserInfo userInfo, string userName, string permissionItemCode) { // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); string userId = userManager.GetId(new KeyValuePair <string, object>(BaseUserEntity.FieldUserName, userName)); BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(dbHelper, userInfo); string permissionItemId = permissionItemManager.GetId(new KeyValuePair <string, object>(BasePermissionItemEntity.FieldCode, permissionItemCode)); if (!String.IsNullOrEmpty(userId) && !String.IsNullOrEmpty(permissionItemId)) { BaseUserPermissionManager userPermissionManager = new BaseUserPermissionManager(dbHelper, userInfo); returnValue = userPermissionManager.Grant(userId, permissionItemId); } } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } return(returnValue); }