Example #1
0
        public IActionResult Index(string wishQuery, string filter, int?page)
        {
            if (string.IsNullOrWhiteSpace(wishQuery) && SessionValueExists("query"))
            {
                wishQuery = GetFromSession <string>("query");
                RemoveFromSession("query");
            }
            ViewBag.Filter = (string.IsNullOrWhiteSpace(wishQuery) ? filter : wishQuery)?.Trim();

            var wishes = _service.GetAll(_user.Id, ViewBag.Filter) as List <Wish>;

            var viewModel = new WishViewModel
            {
                ViewTitle   = "Wish List",
                AlbumWishes = wishes?.Where(x => x.ItemType == ItemType.Album).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                BookWishes  = wishes?.Where(x => x.ItemType == ItemType.Book).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                MovieWishes = wishes?.Where(x => x.ItemType == ItemType.Movie).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                GameWishes  = wishes?.Where(x => x.ItemType == ItemType.Game).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                PopWishes   = wishes?.Where(x => x.ItemType == ItemType.Pop).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                PageSize    = NUM_WISHES_TO_GET
            };

            return(View(viewModel));
        }
 public int GetNumWishes(string userID = "")
 => string.IsNullOrWhiteSpace(userID) ? _wishService.GetAll().Count : _wishService.GetAll(userID).Count;