public ActionResult Edit(int id)
        {
            var movie = _context.Movie.SingleOrDefault(m => m.Id == id);

            if (movie == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new MovieFormViewModel()
            {
                Genres      = _context.Genre.ToList(),
                Id          = movie.Id,
                Name        = movie.Name,
                GenreId     = movie.GenreId,
                ReleaseDate = movie.ReleaseDate,
                //DateAdded = movie.DateAdded,
                NumberInStock = movie.NumberInStock
            };

            return(View("MovieForm", viewModel));
        }
        public ActionResult Save(MovieFormViewModel movieFormViewModel)
        {
            if (!ModelState.IsValid)
            {
                movieFormViewModel.Genres = _context.Genre.ToList();
                return(View("MovieForm", movieFormViewModel));
            }
            if (movieFormViewModel.Id == 0) // new movies
            {
                var movie = new Movie()
                {
                    Name          = movieFormViewModel.Name,
                    GenreId       = movieFormViewModel.GenreId,
                    ReleaseDate   = movieFormViewModel.ReleaseDate,
                    NumberInStock = movieFormViewModel.NumberInStock,
                    DateAdded     = movieFormViewModel.DateAdded
                };
                _context.Movie.Add(movie);
            }
            else
            {
                var movieInDb = _context.Movie.Single(m => m.Id == movieFormViewModel.Id);
                if (movieInDb == null)
                {
                    return(HttpNotFound());
                }
                movieInDb.Name          = movieFormViewModel.Name;
                movieInDb.GenreId       = movieFormViewModel.GenreId;
                movieInDb.ReleaseDate   = movieFormViewModel.ReleaseDate;
                movieInDb.NumberInStock = movieFormViewModel.NumberInStock;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Movies"));
        }