Exemple #1
0
        // Notifications API is asynchronous
        // parameters are for fields in the posted form
        public async Task <ActionResult> Index(SendNotificationPage currentPage,
                                               string from, string to, string subject, string content, string uri,
                                               string when, DateTime?whenDateTime, int?whenDelay)
        {
            IEnumerable <IUIUser> users = userProvider.GetAllUsers(
                pageIndex: 0, pageSize: 30, totalRecords: out int totalRecords);

            INotificationUser sender = await
                                       queryableNotificationUserService.GetAsync(from);

            var receivers = new List <INotificationUser>();

            string[] usernames = to.Split(';');
            foreach (var username in usernames)
            {
                INotificationUser user = await
                                         queryableNotificationUserService.GetAsync(username);

                receivers.Add(user);
            }

            NotificationMessage message;

            if (whenDelay.HasValue)
            {
                message = new DelayedNotificationMessage();
                (message as DelayedNotificationMessage).Delay = TimeSpan.FromMinutes(whenDelay.Value);
            }
            else if (whenDateTime.HasValue)
            {
                message = new ScheduledNotificationMessage();
                (message as ScheduledNotificationMessage).SendAt = whenDateTime.Value;
            }
            else
            {
                message = new NotificationMessage();
            }

            if (!string.IsNullOrWhiteSpace(uri))
            {
                message.Category = new Uri(uri);
            }
            message.ChannelName = Global.NotificationChannel;
            message.Content     = content;
            message.Subject     = subject;
            message.Recipients  = receivers;
            message.Sender      = sender;
            message.TypeName    = Global.NotificationChannel;

            await notifier.PostNotificationAsync(message);

            ViewData["users"] = users.OrderBy(user => user.Username)
                                .Select(user => user.Username).ToArray();
            ViewData["messageSent"] = "Your message was sent successfully.";

            return(View("~/Features/UserNotifications/SendNotificationPage.cshtml",
                        PageViewModel.Create(currentPage)));
        }
Exemple #2
0
        // Notifications API is asynchronous
        // channel parameter can be used to filter messages
        public async Task <ActionResult> Index(
            NotificationsPage currentPage, string channel)
        {
            // always reset the Ignore property to an empty dictionary
            currentPage.Notifications =
                new Dictionary <string, PagedUserNotificationMessageResult>();

            // get a list of the first 30 registered users
            IEnumerable <IUIUser> users = userProvider.GetAllUsers(
                pageIndex: 0, pageSize: 30, totalRecords: out int totalRecords);

            foreach (IUIUser user in users)
            {
                // get an object that represents notifications for each user
                INotificationUser notificationUser = await
                                                     queryableNotificationUserService.GetAsync(user.Username);

                // build a query that includes read, unread, sent, and unsent messages
                var query = new UserNotificationsQuery
                {
                    Read = null, // include read and unread
                    Sent = null, // include sent and unsent
                    User = notificationUser
                };

                // if a channel name is set, use it to filter the notifications
                if (!string.IsNullOrWhiteSpace(channel))
                {
                    ViewData["channel"] = channel;
                    query.ChannelName   = channel;
                }

                // execute the query
                PagedUserNotificationMessageResult result =
                    await userNotificationRepository
                    .GetUserNotificationsAsync(
                        query, startIndex : 0, maxRows : 20);

                // store the query results for the user
                currentPage.Notifications.Add(user.Username, result);
            }

            return(View("~/Features/UserNotifications/NotificationsPage.cshtml",
                        PageViewModel.Create(currentPage)));
        }