public void CurrentPage_SetGreaterThanOrEqualTo1_SetsToValue(int page)
        {
            var model = new GameListViewModel
            {
                CurrentPage = page
            };

            Assert.That(model.CurrentPage, Is.EqualTo(page));
        }
        public void CurrentPage_SetLessThan1_SetsTo1(int page)
        {
            var model = new GameListViewModel
            {
                CurrentPage = page
            };

            Assert.That(model.CurrentPage, Is.EqualTo(1));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Displays a paginated list of games
        /// </summary>
        /// <param name="page">
        ///     The page number being requested
        /// </param>
        /// <returns>
        ///     A paginated list of games
        /// </returns>
        public async Task<ActionResult> Index(int page = 1)
        {
            var viewModel = new GameListViewModel
            {
                CurrentPage = page
            };

            IQueryable<Game> games = db.Games;

            games = FilterOutInternalOnly(games).OrderBy(g => g.Name);

            viewModel.Games = await games.
                Skip((viewModel.CurrentPage - 1) * GamesPerPage).
                Take(GamesPerPage).
                ToListAsync();

            viewModel.TotalPages = 
                (int) Math.Ceiling(await games.CountAsync() / (float) GamesPerPage);

            return View(viewModel);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Processes simple search game search. This is used by the nav-bar search
        /// </summary>
        /// <param name="keyword">
        ///     Fragment of a game title to filter by
        /// </param>
        /// <param name="page">
        ///     The page number being requested
        /// </param>
        /// <returns>
        ///     IQueryable of type 'Game' to Index view of Games controller.
        /// </returns>
        public async Task<ActionResult> Search(string keyword = "", int page = 1)
        {
            var viewModel = new GameListViewModel
            {
                CurrentPage = page
            };

            keyword = keyword.Trim();

            IQueryable<Game> gamesFiltered;

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                gamesFiltered = db.Games
                    .Where(g => g.Name.Contains(keyword));
            }
            else
            {
                gamesFiltered = db.Games;
            }

            gamesFiltered = FilterOutInternalOnly(gamesFiltered).OrderBy(g => g.Name);

            ViewBag.SearchTerm = keyword;

            viewModel.Games = await gamesFiltered.
                Skip((viewModel.CurrentPage - 1) * GamesPerPage).
                Take(GamesPerPage).
                ToListAsync();

            viewModel.TotalPages = 
                (int) Math.Ceiling(await gamesFiltered.CountAsync() / (float) GamesPerPage);

            return View("Index", viewModel);
        }
Ejemplo n.º 5
0
        public async Task<ActionResult> Recommended()
        {
            Member currentMember = await db.Members.FindAsync(idGetter.GetUserId(User.Identity));

            if (currentMember.FavoritePlatforms.Count + currentMember.FavoriteTags.Count == 0)
            {
                this.AddAlert(AlertType.Info, "You do not have any favorite platforms or tags yet.");
                return RedirectToAction("Index", "Manage");
            }
            
            var tagGames = currentMember.FavoriteTags
                .SelectMany(t => t.TaggedGames)
                .Where(g => g.GameAvailabilityStatus != AvailabilityStatus.NotForSale)
                .ToList();

            var platformGames = currentMember.FavoritePlatforms
                .SelectMany(p => p.GameProducts)
                .Select(gp => gp.Game)
                .Where(g => g.GameAvailabilityStatus != AvailabilityStatus.NotForSale)
                .ToList();

            var model = new GameListViewModel
            {
                CurrentPage = 1,
                TotalPages = 1,
                Games = tagGames.Intersect(platformGames)
                        .OrderByDescending(g => g.Tags.Intersect(currentMember.FavoriteTags).Count())
                        .ThenByDescending(g => g.GameSKUs.Min(gp => gp?.ReleaseDate))
                    .Union(
                        tagGames.Except(platformGames)
                        .OrderByDescending(g => g.Tags.Intersect(currentMember.FavoriteTags).Count())
                        .ThenByDescending(g => g.GameSKUs.Min(gp => gp?.ReleaseDate)))
                    .Union(
                        platformGames.Except(tagGames)
                        .OrderByDescending(g => g.GameSKUs.Min(gp => gp?.ReleaseDate)))
                    .Except(currentMember.WebOrders.SelectMany(
                        wo => wo.OrderItems.Select(oi => (oi.Product as GameProduct)?.Game)))
                    .Take(GamesPerPage)
            };

            if (!model.Games.Any())
            {
                string favoritesLink = HtmlHelper.GenerateLink(
                    ControllerContext.RequestContext,
                    RouteTable.Routes,
                    "platforms and tags.",
                    null,
                    "Index",
                    "Manage",
                    null,
                    null);

                this.AddAlert(AlertType.Info, "We don't have any recommendations for you at this time. Try again later or consider updating your favorite ",
                    favoritesLink);
            }

            return View("Index", model);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Processes advanced game searches and displays the results
        /// </summary>
        /// <param name="tags">
        ///     List of tag names to filter by
        /// </param>
        /// <param name="title">
        ///     Title search string to filter by
        /// </param>
        /// <param name="platform">
        ///     Platform Code for the platform to filter by
        /// </param>
        /// <param name="page">
        ///     The page number being requested
        /// </param>
        /// <returns>
        ///     Index view with the filtered results
        /// </returns>
        public async Task<ActionResult> AdvancedSearch(
            List<string> tags, string title = "", string platform = "", int page = 1)
        {
            page = page < 1 ? 1 : page;

            title = title.Trim();
            platform = platform.Trim();
            tags = tags ?? new List<string>();

            if (tags.Count == 0 && title == "" && platform == "")
            {
                AdvancedGameSearchViewModel advancedGameAdvancedGameSearchViewModel = new AdvancedGameSearchViewModel
                {
                    Platforms = await db.Platforms.ToListAsync()
                };

                return View(advancedGameAdvancedGameSearchViewModel);
            }

            for (int i = 0; i < tags.Count; i++)
            {
                string t = tags[i];
                t = t.Trim();
                tags[i] = t;
            }

            // We are doing Or, so we need the first to be false
            var searchPredicate = PredicateBuilder.False<Game>();

            if (!string.IsNullOrWhiteSpace(title))
            {
                // Filter by title
                searchPredicate = searchPredicate.Or(g => g.Name.Contains(title));
            }
                
            if (tags.Count > 0)
            {
                // Filter by tags
                searchPredicate = searchPredicate.Or(g => g.Tags.Any(t => tags.Contains(t.Name)));
            }

            if (!string.IsNullOrWhiteSpace(platform))
            {
                // Filter by platform
                searchPredicate = searchPredicate.Or(
                    g => g.GameSKUs.Any(gs => gs.PlatformCode == platform));
            }

            if (!User.IsEmployeeOrAdmin())
            {
                // Filter out any not for sale games
                // We are doing And, so we need the first to be true
                var roleFilterPredicate = PredicateBuilder.True<Game>().
                    And(g => g.GameAvailabilityStatus != AvailabilityStatus.NotForSale);

                // Equivalent to (conditionAbove && (searchPredicateConditions))
                searchPredicate = roleFilterPredicate.And(searchPredicate);
            }

            IQueryable<Game> gamesFiltered = db.Games.AsExpandable().
                Where(searchPredicate).
                OrderBy(g => g.Name);

            string platformName =
                await db.Platforms.
                    Where(p => p.PlatformCode == platform).
                    Select(p => p.PlatformName).
                    FirstOrDefaultAsync();

            string searchQuery = $"{title}, ";

            if (platformName != null)
            {
                searchQuery += $"{platformName}, ";
            }

            searchQuery += string.Join(", ", tags);
                
            ViewBag.SearchTerm = searchQuery.Trim(',', ' ');

            var gamesListViewModel = new GameListViewModel()
            {
                CurrentPage = page
            };

            gamesListViewModel.Games = await gamesFiltered.
                Skip((gamesListViewModel.CurrentPage - 1) * GamesPerPage).
                Take(GamesPerPage).
                ToListAsync();

            gamesListViewModel.TotalPages = 
                (int) Math.Ceiling(await gamesFiltered.CountAsync() / (float) GamesPerPage);

            return View("Index", gamesListViewModel);
        }