public async Task <bool> SendNotificationAsync(NotifiMessage message) { try { using var response = await new HttpClient().PostAsJsonAsync("https://localhost:44303/api/notifications/SendMessage", message); return(response.IsSuccessStatusCode); } catch (Exception e) { _Logger.LogError("Ошибка отправки сообщения на сервер: {error}", e.Message); return(false); } }
public async Task <IActionResult> SendMessage(NotifiMessage message) { try { var id = message.FromUserId; message.FromUserId = string.Empty; if (message.IsPrivate) { await _HubContext.Clients.Client(id).SendAsync("notification", message); } else { await _HubContext.Clients.All.SendAsync("notification", message); } return(Ok("Notification has been sent succesfully!")); } catch (Exception e) { return(BadRequest($"Error to send notification: {e.Message}")); } }