private void SendNotification(Notification notification) { var context = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>(); var userId = NotificationHub.GetConnectionUserId(notification.UserId); var notificationViewModel = Mapper.Map <NotificationViewModel>(notification); notificationViewModel.UserId = userId; if (userId != null) { context.Clients.Client(userId).addNotification(notificationViewModel); } }
protected void SendNotification(Notification notification) { this.Data.Notifications.Add(notification); this.Data.SaveChanges(); var context = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>(); var userId = NotificationHub.GetConnectionUserId(notification.UserId); var notificationViewModel = Mapper.Map <NotificationViewModel>(notification); notificationViewModel.UserId = userId; if (userId != null) { context.Clients.Client(userId).addNotification(notificationViewModel); } }