Пример #1
0
        public async Task SendNotificationAsync(string fromUserId, string toUserId, string notificationType)
        {
            int notificationId = _notificationsRepository.SaveUserNotification(notificationType, fromUserId, toUserId);
            var connectedId    = _userRepository.GetUserConnectionId(toUserId);

            if (connectedId != null && connectedId.Count > 0)
            {
                // var userInfo = CommonFunctions.GetUserModel(fromUserID);
                int notificationCount = _notificationsRepository.GetUseNNotificationCount(toUserId);
                var notification      = new DtoNotification {
                    NotificationType  = notificationType,
                    NotificationId    = notificationId,
                    NotificationCount = notificationCount,
                    UserId            = fromUserId
                };
                await Clients.Clients(connectedId).SendAsync("ReceiveNotification", notification);
            }
        }
Пример #2
0
        public void SendNotification(string fromUserId, string toUserId, string notificationType)
        {
            int notificationId = _notificationsRepository.SaveUserNotification(notificationType, fromUserId, toUserId);
            var connectedId    = _userRepository.GetUserConnectionId(toUserId);
            var user           = _userRepository.GetUserById(fromUserId);

            if (connectedId != null && connectedId.Count > 0)
            {
                int notificationCount = _notificationsRepository.GetUseNNotificationCount(toUserId);

                DtoNotification notificationViewModel = new DtoNotification();
                notificationViewModel.NotificationType  = notificationType;
                notificationViewModel.NotificationId    = notificationId;
                notificationViewModel.NotificationCount = notificationCount;
                notificationViewModel.UserId            = fromUserId;
                // notificationViewModel.Name = user.FirstName + " " + user.LastName;
                _hubContext.Clients.Clients(connectedId).SendAsync("SendNotification", notificationViewModel);
            }
        }