Ejemplo n.º 1
0
        public IActionResult UpdateUserRelation([FromBody] UpdateUserRelationDto parm)
        {
            // 转化传入内容
            var relations = parm.Relation.Select(m => new Sys_UserRelation
            {
                ID         = GetGUID,
                UserID     = parm.UserID,
                ObjectID   = m.ObjectID,
                ObjectType = m.ObjectType
            }).ToList();

            try
            {
                //开启事务
                _userRelationService.BeginTran();
                //清空权限
                _userRelationService.Delete(m => m.UserID == parm.UserID);
                //插入权限
                _userRelationService.Add(relations);
                _userRelationService.CommitTran();

                #region 更新登录会话记录

                _tokenManager.RefreshSession(parm.UserID);

                #endregion

                return(toResponse(StatusCodeType.Success));
            }
            catch (Exception ex)
            {
                _userRelationService.RollbackTran();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public IActionResult Delete([FromBody] UsersDeleteDto parm)
        {
            if (parm.UserIds.Count <= 0)
            {
                return(toResponse(StatusCodeType.Error, "删除角色 Id 不能为空"));
            }

            // 删除权限记录
            _relationService.Delete(m => parm.UserIds.Contains(m.UserID));
            // 删除用户
            var response = _usersService.Delete(m => parm.UserIds.Contains(m.UserID));

            // 删除登录会话记录
            foreach (var userId in parm.UserIds)
            {
                _tokenManager.RemoveAllSession(userId);
            }

            return(toResponse(response));
        }