예제 #1
0
        public async Task <IActionResult> Index()
        {
            var viewModel = new NotificationsVM();

            if (HttpContext.User != null && HttpContext.User.FindFirst(ClaimTypes.NameIdentifier) != null)
            {
                var     id      = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                AppUser appUser = await _appDbContext.Users
                                  .Include(i => i.Subscriptions)
                                  .ThenInclude(i => i.Region)
                                  .Include(i => i.Subscriptions)
                                  .ThenInclude(i => i.User)
                                  .FirstOrDefaultAsync(m => m.Id == id);

                viewModel.user = appUser;
            }
            else
            {
                viewModel.user = null;
            }
            viewModel.messages = _messageRepository;
            viewModel.regions  = _regionRepository.GetAllRegionToUser().ToList();

            return(View(viewModel));
        }
예제 #2
0
        /// <summary>
        /// Gets a view with a list of all notifications for a user, including a history
        /// </summary>
        /// <returns>View with list of notifications</returns>
        public ActionResult GetNotifications()
        {
            var minDate       = DateTime.Now.AddDays(-2);
            var notifications = UserHelper.GetCurrentDbUser(Context).Notifications
                                .Where(n => !n.IsRead)
                                .Select(n => new NotificationVM
            {
                Id      = n.Id,
                Title   = n.Title,
                Content = n.Content,
                Date    = n.Date,
                IsRead  = n.IsRead
            }).ToList();

            var notificationHistory = UserHelper.GetCurrentDbUser(Context).Notifications
                                      .Where(n => n.IsRead)
                                      .Select(n => new NotificationVM
            {
                Id      = n.Id,
                Title   = n.Title,
                Content = n.Content,
                Date    = n.Date,
                IsRead  = n.IsRead
            }).ToList();

            var model = new NotificationsVM
            {
                Notifications       = notifications,
                NotificationHistory = notificationHistory
            };

            return(View("Notifications", model));
        }
예제 #3
0
        public IActionResult NotificationsPartial(string sort, int page)
        {
            int  entitiesPerPage = 10;
            User owner           = userRepo.GetByEmail(User.Identity.Name);

            IEnumerable <Notification> notifications = notificationRepo.GetAllByUserId(owner.Id);

            if (sort == "track")
            {
                notifications = notifications.Where(n => n.Type == NotificationType.PriceTrack);
            }
            else if (sort == "purchase")
            {
                notifications = notifications.Where(n => n.Type == NotificationType.Purchase);
            }
            else if (sort == "order")
            {
                notifications = notifications.Where(n => n.Type == NotificationType.Sale);
            }
            else if (sort == "report")
            {
                notifications = notifications.Where(n => n.Type == NotificationType.Report);
            }

            List <Notification> list = notifications?.Reverse().Skip((page - 1) * entitiesPerPage).Take(entitiesPerPage).ToList();
            int pageAmount           = (int)Math.Ceiling(list.Count() / (double)entitiesPerPage);

            Console.WriteLine(pageAmount);

            NotificationsVM vm = new NotificationsVM(list, page, pageAmount);

            return(PartialView(vm));
        }
예제 #4
0
        public IActionResult Notifications()
        {
            int  entitiesPerPage = 10;
            User owner           = userRepo.GetByEmail(User.Identity.Name);

            IEnumerable <Notification> notifications = notificationRepo.GetAllByUserId(owner.Id);

            List <Notification> list = notifications?.Reverse().Take(entitiesPerPage).ToList();
            int pageAmount           = (int)Math.Ceiling(list.Count() / (double)entitiesPerPage);

            NotificationsVM vm = new NotificationsVM(list, 1, pageAmount);

            return(View(vm));
        }
예제 #5
0
        public IActionResult AllNotifications()
        {
            var model = new NotificationsVM
            {
                rows = _db.notifications.Where(s => s.ToUserId == _userManager.GetUserId(User))
                       .Select(a => new NotificationsVM.Row
                {
                    NotId  = a.Id,
                    From   = a.FromUserName,
                    What   = a.NotiBody,
                    IsRead = a.IsRead,
                    Detail = a.Message,
                    Date   = a.CreatedDate.ToString("dd.MMMM.yy")
                }).ToList()
            };

            return(View(model));
        }
예제 #6
0
 private void ShowFormNotification()
 {
     if (_formNotification == null)
     {
         _dataWindows                  = new NotificationsVM(this, new NotificationRepository(PluginInitialization._app));
         _formNotification             = new NotificationsV();
         _formNotification.DataContext = _dataWindows;
         _formNotification.Show();
     }
     else
     {
         if (_formNotification.IsVisible)
         {
             _formNotification.Activate();
         }
         else
         {
             _formNotification.Show();
         }
         _dataWindows.ReloadCmd.Execute(null);
     }
 }