public int ClearRole(string systemCode, string userId) { int result = 0; if (string.IsNullOrEmpty(systemCode)) { systemCode = "Base"; } string tableName = systemCode + "UserRole"; BaseUserRoleManager manager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); result += manager.Delete(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, userId)); return(result); }
// // 从角色中删除员工 // #region public int RemoveFormRole(string userId, string roleId) 撤销角色权限 /// <summary> /// 从角色中删除员工 /// </summary> /// <param name="userId">员工主键</param> /// <param name="roleId">角色主键</param> /// <returns>影响行数</returns> public int RemoveFormRole(string userId, string roleId) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, userId)); parameters.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldRoleId, roleId)); string tableName = BaseUserRoleEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "UserRole"; } BaseUserRoleManager userRoleManager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); return(userRoleManager.Delete(parameters)); }
/// <summary> /// 用户是否在某个角色中 /// </summary> /// <param name="systemCode">系统编号</param> /// <param name="userId">用户主键</param> /// <param name="roleCode">角色编号</param> /// <returns>存在</returns> public bool IsInRoleByCode(string systemCode, string userId, string roleCode, bool useBaseRole = true) { bool result = false; if (string.IsNullOrEmpty(systemCode)) { return(false); } if (string.IsNullOrEmpty(userId)) { return(false); } if (string.IsNullOrEmpty(roleCode)) { return(false); } // 2016-01-07 吉日嘎拉 这里用缓存、效率会高 string roleId = BaseRoleManager.GetIdByCodeByCache(systemCode, roleCode); if (string.IsNullOrEmpty(roleId)) { // 2016-01-08 吉日嘎拉 看基础共用的角色里,是否在 if (useBaseRole && !systemCode.Equals("Base")) { roleId = BaseRoleManager.GetIdByCodeByCache("Base", roleCode); } if (string.IsNullOrEmpty(roleId)) { // 表明2个系统里都没了,就真没了 return(false); } } string tableName = systemCode + "UserRole"; BaseUserRoleManager userRoleManager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); result = userRoleManager.Exists(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldDeletionStateCode, 0) , new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, 1) , new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, userId) , new KeyValuePair <string, object>(BaseUserRoleEntity.FieldRoleId, roleId)); return(result); }
public int ClearRole(string userId) { int returnValue = 0; returnValue += this.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, userId), new KeyValuePair <string, object>(BaseUserEntity.FieldRoleId, null)); string tableName = BaseUserRoleEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "UserRole"; } BaseUserRoleManager userRoleManager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); returnValue += userRoleManager.Delete(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, userId)); return(returnValue); }
// // 加入到角色 // #region public string AddToRole(string userId, string roleId) 为了提高授权的运行速度 /// <summary> /// 为了提高授权的运行速度 /// </summary> /// <param name="Id">主键</param> /// <param name="userId">用户主键</param> /// <param name="roleId">角色主键</param> /// <returns>主键</returns> public string AddToRole(string userId, string roleId) { string returnValue = string.Empty; BaseUserRoleEntity userRoleEntity = new BaseUserRoleEntity(); userRoleEntity.UserId = int.Parse(userId); userRoleEntity.RoleId = int.Parse(roleId); userRoleEntity.Enabled = 1; userRoleEntity.DeletionStateCode = 0; string tableName = BaseUserRoleEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "UserRole"; } BaseUserRoleManager userRoleManager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); return(userRoleManager.Add(userRoleEntity)); }
/// <summary> /// 清空角色 /// </summary> /// <param name="systemCode">系统编码</param> /// <param name="userId"></param> /// <returns></returns> public int ClearRole(string systemCode, string userId) { var result = 0; if (string.IsNullOrEmpty(systemCode)) { systemCode = "Base"; } var tableName = systemCode + "UserRole"; var manager = new BaseUserRoleManager(DbHelper, UserInfo, tableName); var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseUserRoleEntity.FieldUserId, userId), new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, 1), new KeyValuePair <string, object>(BaseUserRoleEntity.FieldDeleted, 0) }; result += manager.Delete(parameters); return(result); }
/// <summary> /// 为了提高授权的运行速度 /// </summary> /// <param name="systemCode">系统编号</param> /// <param name="userId">用户主键</param> /// <param name="roleId">角色主键</param> /// <param name="enabled">有效状态</param> /// <returns>主键</returns> public string AddToRoleById(string systemCode, string userId, string roleId, bool enabled = true) { string result = string.Empty; if (string.IsNullOrEmpty(systemCode)) { systemCode = "Base"; } string tableName = string.Empty; if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(roleId)) { BaseUserRoleEntity entity = new BaseUserRoleEntity(); entity.UserId = userId; entity.RoleId = roleId; entity.Enabled = enabled ? 1 : 0; entity.DeletionStateCode = 0; // 2016-03-02 吉日嘎拉 增加按公司可以区别数据的功能。 if (this.DbHelper.CurrentDbType == CurrentDbType.MySql) { entity.CompanyId = BaseUserManager.GetCompanyIdByCache(userId); } // 2015-12-05 吉日嘎拉 把修改人记录起来,若是新增加的 if (this.UserInfo != null) { entity.CreateUserId = this.UserInfo.Id; entity.CreateBy = this.UserInfo.RealName; entity.CreateOn = System.DateTime.Now; entity.ModifiedUserId = this.UserInfo.Id; entity.ModifiedBy = this.UserInfo.RealName; entity.ModifiedOn = System.DateTime.Now; } tableName = systemCode + "UserRole"; BaseUserRoleManager manager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); result = manager.Add(entity); } return(result); }
/// <summary> /// 为了提高授权的运行速度 /// </summary> /// <param name="systemCode">系统编号</param> /// <param name="userId">用户主键</param> /// <param name="roleId">角色主键</param> /// <param name="enabled">有效状态</param> /// <returns>主键</returns> public string AddToRoleById(string systemCode, string userId, string roleId, bool enabled = true) { var result = string.Empty; if (string.IsNullOrEmpty(systemCode)) { systemCode = "Base"; } if (ValidateUtil.IsInt(userId) && ValidateUtil.IsInt(roleId)) { var entity = new BaseUserRoleEntity { UserId = userId.ToInt(), RoleId = roleId.ToInt(), Enabled = enabled ? 1 : 0 }; var tableName = systemCode + "UserRole"; //新增或激活 result = new BaseUserRoleManager(DbHelper, UserInfo, tableName).AddOrActive(entity); } return(result); }