public async Task <ActionResult> Index(string genreName, string platformName, int page = 1, GamesSortOrder sortOrder = GamesSortOrder.ByDateAscending) { ICollection <GameCardViewModel> games = new List <GameCardViewModel>(); if (genreName != null) { games = _mapper.Map <ICollection <GameDTO>, ICollection <GameCardViewModel> > (await _gameService.GetGamesByGenreAsync(genreName)); } if (platformName != null) { games = _mapper.Map <ICollection <GameDTO>, ICollection <GameCardViewModel> > (await _gameService.GetGamesByPlatformAsync(platformName)); } if (platformName == null && genreName == null) { games = _mapper.Map <ICollection <GameDTO>, ICollection <GameCardViewModel> > (await _gameService.GetGamesAsync()); } games = SortGames(sortOrder, games); GameCardListViewModel gameCardList = await CreateGameCardList(page, games); return(View(gameCardList)); }
public static IEnumerable<Game> MostRecent(int howMany, GamesSortOrder sortOrder) { var games = _games.AsEnumerable() .OrderBy(g => g.WhenPlayed) .Reverse() .Take(howMany); if (sortOrder == GamesSortOrder.MostRecentLast) return games.Reverse(); return games; }
public static IEnumerable <Game> MostRecent(int howMany, GamesSortOrder sortOrder) { var games = _games.AsEnumerable() .Reverse() .Take(howMany); if (sortOrder == GamesSortOrder.MostRecentLast) { return(games.Reverse()); } return(games); }
public ICollection <GameCardViewModel> SortGames(GamesSortOrder sortOrder, ICollection <GameCardViewModel> games) { switch (sortOrder) { case GamesSortOrder.ByDateDescending: return(games.Reverse().ToList()); case GamesSortOrder.ByRatingAscending: return(games.OrderBy(game => game.Rating).ToList()); case GamesSortOrder.ByRatingDescending: return(games.OrderByDescending(game => game.Rating).ToList()); default: return(games); } }
public static IEnumerable<Game> MostRecent(int howMany, GamesSortOrder sortOrder) { var games = All.Reverse().Take(howMany); return sortOrder == GamesSortOrder.MostRecentLast ? games.Reverse() : games; }
public static IEnumerable <Game> MostRecent(int howMany, GamesSortOrder sortOrder) { var games = All.Reverse().Take(howMany); return(sortOrder == GamesSortOrder.MostRecentLast ? games.Reverse() : games); }