示例#1
0
 public ActionResult <Stock> GetStock(string stock_code)
 {
     try
     {
         var result = StockBotService.GetStock(stock_code);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
示例#2
0
        public async Task Send(long chatRoomId, string messageBody, string unique_name)
        {
            var text = messageBody.ToLower();
            var user = await _userManager.FindByEmailAsync(unique_name);

            var message = new Message
            {
                ChatroomId   = chatRoomId,
                MessageSent  = messageBody,
                SendDate     = DateTime.Now,
                SenderUserId = user != null ? user.Id : 0
            };
            await Clients.All.SendAsync(chatRoomId.ToString(), user?.UserName, message);

            await Clients.Group(message.ChatroomId.ToString()).SendAsync($"User_{unique_name}", unique_name, messageBody);

            if (text.Contains("/stock="))
            {
                text = text.Replace("/stock=", "");
                var response = await _stockBotService.GetStock(text.ToString());

                if (response != null)
                {
                    message.MessageSent = $"{response.Symbol.ToUpper()} quote is $ {response.Open} per share.";
                    await Clients.All.SendAsync(chatRoomId.ToString(), "Bot_Stock", message);

                    await Clients.Group(message.ChatroomId.ToString()).SendAsync("Bot_Stock", messageBody);
                }
                else
                {
                    message.MessageSent = $"{text.ToString()} not found";
                    await Clients.All.SendAsync(chatRoomId.ToString(), "Bot_Stock", message);

                    await Clients.Group(message.ChatroomId.ToString()).SendAsync("OnMetadataMessage", messageBody);
                }
            }
            else
            {
                _messageRepository.Add(message);
            }
        }