コード例 #1
0
        public async Task NotifyAsync(NotifierData data)
        {
            var identity = GetSettingsIdentity(data);

            var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity);

            if (settings != null && settings.IsEnabled)
            {
                var receivers = (await _intranetMemberService.GetManyAsync(data.ReceiverIds)).ToList();
                foreach (var receiverId in data.ReceiverIds)
                {
                    var user = receivers.Find(receiver => receiver.Id == receiverId);

                    var message = _notificationModelMapper.Map(data.Value, settings.Template, user);

                    _mailService.SendAsync(message);

                    _notificationRepository.AddAsync(new Sql.Notification
                    {
                        Id           = Guid.NewGuid(),
                        Date         = DateTime.UtcNow,
                        IsNotified   = true,
                        IsViewed     = false,
                        Type         = data.NotificationType.ToInt(),
                        NotifierType = NotifierTypeEnum.EmailNotifier.ToInt(),
                        Value        = new { message }.ToJson(),
                        ReceiverId   = receiverId
                    });
                }
            }
        }
コード例 #2
0
        public async Task NotifyAsync(NotifierData data)
        {
            var identity = new ActivityEventIdentity(CommunicationTypeEnum.Member, data.NotificationType).AddNotifierIdentity(Type);
            var settings = await _notificationSettingsService.GetAsync <PopupNotifierTemplate>(identity);

            if (settings != null && settings.IsEnabled)
            {
                var receivers = await _intranetMemberService.GetManyAsync(data.ReceiverIds);

                var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r));
                await _notificationsService.NotifyAsync(messages);
            }
        }
コード例 #3
0
        public async Task NotifyAsync(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 = await _notificationSettingsService.GetAsync <UiNotifierTemplate>(identity);

            var desktopSettingsIdentity = new ActivityEventIdentity(settings.ActivityType, settings.NotificationType)
                                          .AddNotifierIdentity(NotifierTypeEnum.DesktopNotifier);
            var desktopSettings = await _notificationSettingsService.GetAsync <DesktopNotifierTemplate>(desktopSettingsIdentity);

            if (!settings.IsEnabled && !desktopSettings.IsEnabled)
            {
                return;
            }

            var receivers = (await _intranetMemberService.GetManyAsync(data.ReceiverIds));

            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;
                }
                return(uiMsg);
            });
            await _notificationsService.NotifyAsync(messages);
        }
コード例 #4
0
        protected virtual async Task <IEnumerable <(Guid Id, string DisplayedName)> > GetManyNamesAsync(IEnumerable <Guid> usersIds)
        {
            var users = await _intranetMemberService.GetManyAsync(usersIds);

            return(users.Select(el => (el.Id, el.DisplayedName)));
        }