public Task<List<NotificationDto>> GetRecentActivity(long userId, int offset = 0) { return Task.Run(() => { var notificationsDto = new List<NotificationDto>(); using (var unitOfWork = _unitOfWorkFactory.NewUnitOfWork()) { var _notificationRepository = unitOfWork.GetRepository<Notification>(); var notifications = _notificationRepository.GetAll(n => n.User.Id == userId).OrderByDescending(s => s.Id).Skip(offset).Take(15).ToList(); foreach (var notification in notifications) { var notificationDto = new NotificationDto(); Mapper.Map(notification, notificationDto); notificationDto.Message = GetMessage(notification); notificationsDto.Add(notificationDto); } } return notificationsDto; }); }
public void SendNotification(long id, NotificationDto notification, List<long> listReceivers ) { var list = ConnectedUsers.Where(s => listReceivers.Contains(s.UserId)).Select(s => s.ConnectionId).ToList(); if (list.Count > 0) { Clients.Clients(list).newNotification(notification); //foreach (var socketId in list) //{ // Clients.Client(socketId).newNotification(notification); //} } }
public Notification CreateNotification(Notifications type, User user, User recentlyUser, Playlist recentlyPlaylist) { var notification = new Notification { NotificationType = type, User = user, RecentlyUser = recentlyUser, RecentlyPlaylist = recentlyPlaylist, NotificationDate = DateTime.Now }; var notificationDto = new NotificationDto(); Mapper.Map(notification, notificationDto); notificationDto.Message = GetMessage(notification); List<long> list = user.Followers.Select(s => s.Id).ToList(); _notificationHub.SendNotification(user.Id, notificationDto, list); return notification; }