Exemplo n.º 1
0
        public async Task <ActionResult> Home(int?status, int page = 1)
        {
            var notificationStatus = (NotificationStatus?)status;
            var response           = await mediator.SendAsync(new GetExportNotificationsByUser(page, notificationStatus));

            var model = new UserNotificationsViewModel(response);

            model.SelectedNotificationStatus = notificationStatus;

            return(View(model));
        }
        public async Task <UserNotificationsViewModel> GetNotificationsForUser()
        {
            var user = await GetCurrentUserAsync();

            var notifications = _context.NotificationUser.Include(n => n.Notification).Where(x => x.UserId == user.Id).ToList();

            List <NotificationUserViewModel> notificationList = _mapper.Map <List <NotificationUser>, List <NotificationUserViewModel> >(notifications);

            var orderedNotificationList = notificationList.OrderByDescending(x => x.Notification.DateTime).ToList();

            foreach (var notification in notificationList)
            {
                var userLink = _context.Users.FirstOrDefault(x => x.Id == notification.UserId);

                notification.Notification.FullNameLink = userLink.FirstName + " " + userLink.LastName;
            }

            UserNotificationsViewModel model = new UserNotificationsViewModel()
            {
                Notifications = orderedNotificationList
            };

            return(model);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> HomePost(UserNotificationsViewModel model, string button, int page = 1)
        {
            if (button == "search")
            {
                if (!string.IsNullOrWhiteSpace(model.SearchTerm))
                {
                    try
                    {
                        var id = await mediator.SendAsync(new GetNotificationIdByNumber(model.SearchTerm));

                        return(id.HasValue ? RedirectToAction("Index", "Options", new { area = "NotificationApplication", id }) : RedirectToAction("NotFound"));
                    }
                    catch (SecurityException)
                    {
                        return(RedirectToAction("NotFound"));
                    }
                }

                ModelState.AddModelError("SearchTerm", "Please enter a valid search term");
                return(await Home(null, page));
            }

            return(RedirectToAction("Home", new { page = 1, status = (int?)model.SelectedNotificationStatus }));
        }