コード例 #1
0
        public async Task SendMessage([FromBody] MessageData data)
        {
            var userName = User.Identity.Name;
            var userId   = int.Parse(User.Claims.First(claim => claim.Type == "id").Value);
            var user     = new User(userId, userName);
            var message  = new Message(user, data.Text);

            chatData.Add(message);
            await _hubContext.Clients.All.SendAsync("ReceiveMessage", message);
        }