public async Task SendMessageTo(ChatMessage message) { try { var connection = await connectionContext.GetConnectionByUserId(message.RecieverId); if (connection != null) { await Clients.Client(connection.ConnectionID).SendAsync("ReceiveMessageFrom", message); } else { this.SendByPushNotification(message.SenderId, message.Message); } await chatContext.AddMessageMyConversation(new ChatMessage { MessageId = message.MessageId, Created = DateTime.Now, Message = message.Message, Readed = false, SenderId = message.SenderId, RecieverId = message.RecieverId }); } catch (Exception ex) { SendError(Context.ConnectionId, ex.Message); } }