示例#1
0
        public async Task SendMessage(string author, string text)
        {
            await chatRepository.AddMessage(author, text);

            var messages = (await chatRepository.ChatMessagesOrderedByDateAsync()).ToEnumerable();
            await Clients.All.SendAsync("sendMessage", messages.Select(x => new { x.Author, x.Text, x.CreationDate }));
        }
        public async Task <IActionResult> AllMessages()
        {
            var messages = (await chatRepository.ChatMessagesOrderedByDateAsync()).ToEnumerable();

            return(Ok(messages.Select(x => new ChatMessage {
                Author = x.Author, Text = x.Text, CreationDate = x.CreationDate
            })));
        }