Пример #1
0
        public override async Task OnConnectedAsync()
        {
            var userId    = Guid.Parse(Context.User.Identity.Name ?? string.Empty);
            var channelId = Context.User.FindFirst("ChannelId").Value;

            var user = await _applicationDbContext.Users.SingleOrDefaultAsync(u => u.Id == userId);

            user.Connections++;

            var permission = _userPermissionRepository.GetPermission(userId);

            if (permission == null)
            {
                permission = new UserPermission {
                    AllowControl = true
                };
                _userPermissionRepository.SetPermission(userId, permission);
            }

            var hostConnectionId = _hostConnectionRepository.GetConnection(channelId);

            if (user.Connections == 1 && hostConnectionId != null)
            {
                await _hostHubContext.SendUserConnected(hostConnectionId,
                                                        new ChannelUserMsg { Id = user.Id, Name = user.Name, AllowControl = permission.AllowControl });
            }

            await _applicationDbContext.SaveChangesAsync();

            await Groups.AddToGroupAsync(Context.ConnectionId, channelId);
        }
Пример #2
0
 public Task SetUserPermission(UserPermissionMsg userPermissionMsg)
 {
     _userPermissionRepository.SetPermission(userPermissionMsg.UserId,
                                             new UserPermission {
         AllowControl = userPermissionMsg.AllowControl
     });
     return(Task.CompletedTask);
 }