Beispiel #1
0
        public void Connect(string name)
        {
            var clientId = Context.ConnectionId;
            var u        = _userRepository.UserIsExist(name);

            if (!_users.Exists(x => x.UserId == u.UserId))
            {
                var newOnlineUser = new ConnectionInfo
                {
                    UserId       = u.UserId,
                    UserName     = u.FullName,
                    ConnectionId = clientId,
                    Date         = DateTime.Now,
                    Status       = ConnectionStatus.Connect
                };
                _users.Add(newOnlineUser);
                _chatRepository.AddInfo(newOnlineUser);
                // Send the current users
                Clients.Caller.onConnected(clientId, u.FullName, _users);
                Clients.AllExcept(clientId).onNewUserConnected(u.UserId, u.FullName);
            }
            else
            {
                Clients.Caller.onConnected(clientId, u.FullName, _users);
            }
        }