コード例 #1
0
        // GET: Movies
        public async Task <IActionResult> Index(string movieGenre, string searchString)
        {
            var movies = from m in _context.Movie
                         select m;

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

            if (!String.IsNullOrEmpty(movieGenre))
            {
                movies = movies.Where(x => x.Genre == movieGenre);
            }

            var movieGenreVM = new MovieGenreViewModel();

            movieGenreVM.movieGenre   = movieGenre;
            movieGenreVM.searchString = searchString;
            var genreService = new Services.GenreService();

            movieGenreVM.genres = genreService.GetGenres();
            movieGenreVM.movies = await movies.ToListAsync();

            return(View(movieGenreVM));
        }
コード例 #2
0
        // GET: Movies/Create
        public IActionResult Create()
        {
            var genreService = new Services.GenreService();

            ViewBag.genreList = genreService.GetGenres();

            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("ID,Genre,Price,ReleaseDate,Title")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            var genreService = new Services.GenreService();

            ViewBag.genreList = genreService.GetGenres();
            return(View(movie));
        }