Ejemplo n.º 1
0
        public ActionResult Save([Bind(Exclude = "Id")] Movies movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieModelForm(movie)
                {
                    Genres = _context.Genres.ToList()
                };

                return(View("New", viewModel));
            }

            if (movie.Id == 0)
            {
                movie.DateAdded = DateTime.Now;
                _context.Movies.Add(movie);
            }
            else
            {
                var moviedb = _context.Movies.Single(m => m.Id == movie.Id);
                moviedb.Name          = movie.Name;
                moviedb.GenreId       = movie.GenreId;
                moviedb.NumberInStock = movie.NumberInStock;
                moviedb.ReleaseDate   = movie.ReleaseDate;
            }
            _context.SaveChanges();



            return(RedirectToAction("Index", "Movies"));
        }
Ejemplo n.º 2
0
        public ActionResult New()
        {
            var genres    = _context.Genres.ToList();
            var viewmodel = new MovieModelForm()
            {
                Genres = genres
            };

            return(View("new", viewmodel));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int Id)
        {
            var movie = _context.Movies.SingleOrDefault(m => m.Id == Id);

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

            var viewmodel = new MovieModelForm()
            {
                Genres = _context.Genres.ToList()
            };

            return(View("new", viewmodel));
        }