Ejemplo n.º 1
0
        // GET: Games
        public async Task <IActionResult> Index(string gameGenre, string searchString)
        {
            IQueryable <string> genreQuery = from g in _context.Game
                                             orderby g.Genre
                                             select g.Genre;

            var games = from g in _context.Game
                        select g;

            if (!string.IsNullOrEmpty(searchString))
            {
                games = games.Where(s => s.Title.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(gameGenre))
            {
                games = games.Where(x => x.Genre == gameGenre);
            }

            GameGenreViewModel gameGenreVM = new GameGenreViewModel
            {
                Genres = new SelectList(await genreQuery.Distinct().ToListAsync()),
                Games  = await games.ToListAsync()
            };

            return(View(gameGenreVM));
        }
Ejemplo n.º 2
0
        //This checks filter!
        //[HttpPost]
        //public string Index(string searchString, bool notUsed)
        //{
        //    return "From [HttpPost]Index: filter on " + searchString;
        //}

        // GET: Games
        //Wymaga u¿ycia using Microsoft.AspNetCore.Mvc.Rendering;
        public async Task <IActionResult> Index(string searchString, string gameGenre)
        {
            //U¿ycie LINQ do zdobycia listy gatunków
            IQueryable <string> genreQuery = from g in _context.Game
                                             orderby g.gatunek
                                             select g.gatunek;
            var games = from g in _context.Game
                        select g;

            if (!String.IsNullOrEmpty(searchString))
            {
                games = games.Where(s => s.tytul.Contains(searchString));
            }
            if (!String.IsNullOrEmpty(gameGenre))
            {
                games = games.Where(g => g.gatunek == gameGenre);
            }

            var gameGenreVM = new GameGenreViewModel();

            gameGenreVM.genres = new SelectList(await genreQuery.Distinct().ToListAsync());
            gameGenreVM.games  = await games.ToListAsync();

            return(View(gameGenreVM));
        }
Ejemplo n.º 3
0
        // GET: Games
        public async Task <IActionResult> Index(string gameGenre, string searchString, string gameConsole)
        {
            IQueryable <string> genreQuery = from m in _context.Game
                                             orderby m.Genre
                                             select m.Genre;

            IQueryable <string> consolesQuery = from m in _context.Console
                                                orderby m.Name
                                                select m.Name;

            var games = from m in _context.Game
                        select m;

            if (!String.IsNullOrEmpty(searchString))
            {
                games = games.Where(s => s.Title.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(gameGenre))
            {
                games = games.Where(x => x.Genre == gameGenre);
            }

            if (!String.IsNullOrEmpty(gameConsole))
            {
                games = games.Where(x => x.Console == gameConsole);
            }

            var gameGenreVM = new GameGenreViewModel();

            gameGenreVM.genres   = new SelectList(await genreQuery.Distinct().ToListAsync());
            gameGenreVM.consoles = new SelectList(await consolesQuery.Distinct().ToListAsync());
            gameGenreVM.games    = await games.ToListAsync();

            return(View(gameGenreVM));
        }