public IActionResult AltList(string Games, string Genre, string filter, string platform, int GamesPage = 1) { IEnumerable <Games> ItemList; int ListCount; IOrderedQueryable <string> AllGenres = repository.Games .Select(x => x.Genre) .Distinct() .OrderBy(x => x); if (AllGenres.Contains(Genre)) { switch (platform) { case "Windows": ItemList = repository.Games.Where(g => g.Genre == Genre && g.PlatformWindows == true).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.Genre == Genre && e.PlatformWindows == true).Count(); break; case "Linux": ItemList = repository.Games.Where(g => g.Genre == Genre && g.PlatformLinux == true).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.Genre == Genre && e.PlatformLinux == true).Count(); break; case "Mac": ItemList = repository.Games.Where(g => g.Genre == Genre && g.PlatformMac == true).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.Genre == Genre && e.PlatformMac == true).Count(); break; default: ItemList = repository.Games.Where(g => g.Genre == Genre).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.Genre == Genre).Count(); break; } return(View(new GamesListViewModel { Games = ItemList, PagingInfo = new PagingInfo { CurrentPage = GamesPage, ItemsPerPage = PageSize, TotalItems = ListCount }, CurrentCategory = Genre })); } else { switch (platform) { case "Windows": ItemList = repository.Games.Where(g => g.QueryName.Contains(Genre) && g.PlatformWindows == true).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.QueryName.Contains(Genre) && e.PlatformWindows == true).Count(); break; case "Linux": ItemList = repository.Games.Where(g => g.QueryName.Contains(Genre) && g.PlatformLinux == true).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.QueryName.Contains(Genre) && e.PlatformLinux == true).Count(); break; case "Mac": ItemList = repository.Games.Where(g => g.QueryName.Contains(Genre) && g.PlatformMac == true).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.QueryName.Contains(Genre) && e.PlatformMac == true).Count(); break; default: ItemList = repository.Games.Where(g => g.QueryName.Contains(Genre)).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); ListCount = repository.Games.Where(e => e.QueryName.Contains(Genre)).Count(); break; } return(View(new GamesListViewModel { Games = ItemList, PagingInfo = new PagingInfo { CurrentPage = GamesPage, ItemsPerPage = PageSize, TotalItems = ListCount }, CurrentCategory = Genre })); } }
public IActionResult SortList(string genre, string SortOn, string ascordesc, int GamesPage = 1) { IEnumerable <Games> ItemList; IOrderedQueryable <string> AllGenres = repository.Games .Select(x => x.Genre) .Distinct() .OrderBy(x => x); if (AllGenres.Contains(genre)) { if (ascordesc == "Asc") { switch (SortOn) { case "PriceFinal": ItemList = repository.Games.Where(g => g.Genre == genre).OrderBy(g => g.PriceFinal).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; case "QueryName": ItemList = repository.Games.Where(g => g.Genre == genre).OrderBy(g => g.QueryName).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; case "ReleaseDate": ItemList = repository.Games.Where(g => g.Genre == genre).OrderBy(g => DateTime.Parse(g.ReleaseDate)).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; default: ItemList = repository.Games.Where(g => g.Genre == genre).OrderBy(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; } } else { switch (SortOn) { case "PriceFinal": ItemList = repository.Games.Where(g => g.Genre == genre).OrderByDescending(g => g.PriceFinal).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; case "QueryName": ItemList = repository.Games.Where(g => g.Genre == genre).OrderByDescending(g => g.QueryName).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; case "ReleaseDate": ItemList = repository.Games.Where(g => g.Genre == genre).OrderByDescending(g => DateTime.Parse(g.ReleaseDate)).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; default: ItemList = repository.Games.Where(g => g.Genre == genre).OrderByDescending(g => g.Metacritic).Skip((GamesPage - 1) * PageSize).Take(PageSize); break; } } return(View(new GamesListViewModel { Games = ItemList, PagingInfo = new PagingInfo { CurrentPage = GamesPage, ItemsPerPage = PageSize, TotalItems = genre == null ? repository.Games.Count() : repository.Games.Where(e => e.Genre == genre).Count() }, CurrentCategory = genre })); } else { if (ascordesc == "Asc") { switch (SortOn) { case "PriceFinal": ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderBy(g => g.PriceFinal); break; case "QueryName": ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderBy(g => g.QueryName); break; case "ReleaseDate": ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderBy(g => DateTime.Parse(g.ReleaseDate)); break; default: ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderBy(g => g.Metacritic); break; } } else { switch (SortOn) { case "PriceFinal": ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderByDescending(g => g.PriceFinal); break; case "QueryName": ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderByDescending(g => g.QueryName); break; case "ReleaseDate": ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderByDescending(g => DateTime.Parse(g.ReleaseDate)); break; default: ItemList = repository.Games.Where(g => g.QueryName.Contains(genre)).OrderByDescending(g => g.Metacritic); break; } } return(View(new GamesListViewModel { Games = ItemList, PagingInfo = new PagingInfo { CurrentPage = 1, ItemsPerPage = PageSize, TotalItems = genre == null ? repository.Games.Count() : repository.Games.Where(e => e.QueryName.Contains(genre)).Count() }, CurrentCategory = genre })); } }