public async Task <IActionResult> SendMessage(SendMessageVm sendMessageVm) { if (sendMessageVm.RecepientConnectionId == "0") { // Отправить всем клиентам сообщение. await WorkHub.Clients.All.SendAsync("Alert", sendMessageVm.Message); } else { // Отправить сообщение конкретному пользователю. await WorkHub.Clients.Client(sendMessageVm.RecepientConnectionId).SendAsync("Alert", sendMessageVm.Message); } return(RedirectToAction("SendMessage")); }
public IActionResult SendMessage() { List <Recepient> recepients = ConnectedUserProvider.ConnectedUsers .Select(x => new Recepient(x.ConnectionId, x.Name)) .ToList(); recepients.Insert(0, new Recepient("0", "Все")); var sendMessageVm = new SendMessageVm() { Recipients = recepients }; return(View(sendMessageVm)); }