public async Task <IActionResult> GetNotifications([FromRoute, Required] string appName, [FromRoute, Required] string phoneNumber, int limit = 20, int offset = 0) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var query = new UserNotificationsQuery { PhoneNumber = phoneNumber, AppName = appName, Limit = limit, Offset = offset }; try { var result = await mediator.Send(query); return(Ok(result)); } catch (InvalidAppException) { return(BadRequest("InvalidApp")); } }
// 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))); }