Ejemplo n.º 1
0
        public ActionResult New(string s)
        {
            ModifyMovieViewModel model = new ModifyMovieViewModel
            {
                Genres = _context.Genres.ToList()
            };

            return(View("ModifyMovie", model));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            ModifyMovieViewModel model = new ModifyMovieViewModel
            {
                Movie  = _context.Movies.SingleOrDefault(m => m.Id == id),
                Genres = _context.Genres.ToList()
            };

            return(View("ModifyMovie", model));
        }
Ejemplo n.º 3
0
        //[HttpPost]
        public ActionResult Save(ModifyMovieViewModel movieViewModel)
        {
            if (movieViewModel.Movie.Id.Equals(0))
            {
                _context.Movies.Add(movieViewModel.Movie);
            }
            else
            {
                var oldMovie = _context.Movies.SingleOrDefault(m => m.Id == movieViewModel.Movie.Id);
                if (oldMovie != null)
                {
                    oldMovie.DateAdded     = movieViewModel.Movie.DateAdded;
                    oldMovie.GenreId       = movieViewModel.Movie.GenreId;
                    oldMovie.Name          = movieViewModel.Movie.Name;
                    oldMovie.NumberInStock = movieViewModel.Movie.NumberInStock;
                    oldMovie.ReleaseDate   = movieViewModel.Movie.ReleaseDate;
                }
            }
            _context.SaveChanges();

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