示例#1
0
        public async Task <IActionResult> AddUserNotification([FromRoute] string id, [FromBody] NotificationMessage messsage)
        {
            await m_service.AddUserNotifications(new UserNotificationBulkRequest
            {
                UserIds = new string[] { id },
                Message = messsage
            });

            return(NoContent());
        }
示例#2
0
        public void AddUserNotificationPositive()
        {
            const string title   = "Hello";
            const string text    = "My message";
            const string creator = "Notification";
            User         user    = Context.Users.First();

            UserNotificationBulkRequest request = new UserNotificationBulkRequest
            {
                UserIds = new List <string> {
                    user.Id
                },
                Message = new Logic.Models.NotificationMessage
                {
                    Title    = title,
                    Text     = text,
                    Creator  = creator,
                    Severity = Logic.Models.Enums.Severity.Informational
                }
            };

            m_notificationService.AddUserNotifications(request);

            Data.Models.Notification notification = Context.Notifications.SingleOrDefault(x => x.Title == title);

            Assert.IsNotNull(notification);
            Assert.AreEqual(user.Id, notification.UserId);
            Assert.AreEqual(text, notification.Text);
            Assert.AreEqual(creator, notification.Creator);
            Assert.AreEqual(NotificationType.Notification, notification.Type);
            Assert.AreEqual(false, notification.IsClosed);
        }
        public async Task NotifySubsribers(string theme, string text, Logic.Models.Enums.Severity severity)
        {
            Data.Models.Subscription subscription = await m_context.Subscriptions
                                                    .AsNoTracking()
                                                    .Include(x => x.UserSubscriptions.Where(u => u.IsSubscribed == true))
                                                    .SingleOrDefaultAsync(x => x.Theme == theme);

            if (subscription == null)
            {
                throw new System.Exception();
            }

            NotificationMessage message = new NotificationMessage
            {
                Title    = theme,
                Text     = text,
                Severity = severity
            };

            UserNotificationBulkRequest notificationRequest = new UserNotificationBulkRequest
            {
                UserIds = subscription.UserSubscriptions.Where(x => x.ClientNotificationNeeded == true).Select(x => x.UserId),
                Message = message
            };

            UserNotificationBulkRequest emailRequest = new UserNotificationBulkRequest
            {
                UserIds = subscription.UserSubscriptions.Where(x => x.EmailNotificationNeeded == true).Select(x => x.UserId),
                Message = message
            };

            if (notificationRequest.UserIds.Count() != 0)
            {
                await m_notificationService.AddUserNotifications(notificationRequest);
            }
            if (emailRequest.UserIds.Count() != 0)
            {
                await m_emailNotificationService.SendEmailNotifications(emailRequest);
            }
        }
        public async Task ConsumeAsync(UserNotificationMessage message)
        {
            UserNotificationBulkRequest request = new UserNotificationBulkRequest
            {
                UserIds = new string[] { message.UserId },
                Message = new NotificationMessage
                {
                    Title    = message.Title,
                    Text     = message.Text,
                    Severity = m_mapper.Map <Logic.Models.Enums.Severity>(message.Severity)
                }
            };

            if (message.NotificationType == NotificationType.EmailNotification)
            {
                await m_emailService.SendEmailNotifications(request);
            }
            else if (message.NotificationType == NotificationType.Notification)
            {
                await m_notificationService.AddUserNotifications(request);
            }
        }