public virtual ActionResult Index(int page = 1) { var take = page * ItemsPerPage; var(notifications, totalCount) = _uiNotifierService.GetMany(_intranetMemberService.GetCurrentMemberId(), take); var notificationsArray = notifications.ToArray(); var notNotifiedNotifications = notificationsArray.Where(el => !el.IsNotified).ToArray(); if (notNotifiedNotifications.Length > 0) { _uiNotifierService.Notify(notNotifiedNotifications); } var notificationsViewModels = notificationsArray.Select(MapNotificationToViewModel).ToArray(); var result = new NotificationListViewModel { Notifications = notificationsViewModels, BlockScrolling = totalCount <= take }; return(PartialView(ListViewPath, result)); }
public void Notify(NotifierData data) { var isCommunicationSettings = data.NotificationType.In( NotificationTypeEnum.CommentLikeAdded, NotificationTypeEnum.MonthlyMail, IntranetActivityTypeEnum.ContentPage); var identity = new ActivityEventIdentity(isCommunicationSettings ? CommunicationTypeEnum.CommunicationSettings : data.ActivityType, data.NotificationType) .AddNotifierIdentity(Type); var settings = _notificationSettingsService.Get <UiNotifierTemplate>(identity); var desktopSettingsIdentity = new ActivityEventIdentity(settings.ActivityType, settings.NotificationType) .AddNotifierIdentity(NotifierTypeEnum.DesktopNotifier); var desktopSettings = _notificationSettingsService.Get <DesktopNotifierTemplate>(desktopSettingsIdentity); if (!settings.IsEnabled && !desktopSettings.IsEnabled) { return; } var receivers = _intranetMemberService.GetMany(data.ReceiverIds).ToList(); var messages = receivers.Select(receiver => { var uiMsg = _notificationModelMapper.Map(data.Value, settings.Template, receiver); if (desktopSettings.IsEnabled) { var desktopMsg = _desktopNotificationModelMapper.Map(data.Value, desktopSettings.Template, receiver); uiMsg.DesktopTitle = desktopMsg.Title; uiMsg.DesktopMessage = desktopMsg.Message; uiMsg.IsDesktopNotificationEnabled = true; if (uiMsg.NotifierId.HasValue) { uiMsg.NotifierPhotoUrl = _intranetMemberService.Get(uiMsg.NotifierId.Value)?.Photo; } } return(uiMsg); }); _notificationsService.Notify(messages); }