Beispiel #1
0
        /// <summary>
        /// 保存实体更改
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="roleIds"></param>
        /// <returns></returns>
        public bool SaveUserRoll(string userId, string[] roleIds)
        {
            var opera        = UserHelper.GetOperator();
            var userid       = opera.Id;
            var list         = fsql.Select <SysRoleUser>().Where(p => p.UserId == userid).ToList();// GetList(userId);
            var existRoleIds = list.Select(x => x.RoleId).ToList();

            roleIds = roleIds ?? new string[0];

            var toDeleteList = existRoleIds.Except(roleIds).ToList();
            var toCreateList = roleIds.Except(existRoleIds).ToList();

            if (toDeleteList.Count > 0)
            {
                var count = fsql.Select <SysRoleUser>().Where(p => p.UserId == userId && toDeleteList.Contains(p.RoleId)).ToDelete().ExecuteAffrows();

                //var sql = new StringBuilder("delete from sys_user_role where user_id='" + userId + "' and role_id in ('" + string.Join("','", toDeleteList) + "')");
                //fsql.Select<OneValue>().WithSql(sql.ToString()).First();
            }

            foreach (var item in toCreateList)
            {
                var entity = new SysRoleUser()
                {
                    RoleId   = item,
                    UserId   = userId,
                    CreateBy = userid
                };
                Ser_SysRoleUser.InsertOrUpdateExt(entity);
            }

            //清除用户对应的权限缓冲
            var userName = fsql.Select <SysUser>().Where(p => p.Id == userId).First().LoginName;

            UserHelper.DeleteUserAuthRedis(userName);

            return(true);
        }
Beispiel #2
0
 public List <SysRoleUser> GetUserRoleList(string userId)
 {
     return(Ser_SysRoleUser.Where(x => x.UserId == userId).ToList());
 }