public ActionResult Save(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieFormModel(movie)
                {
                    Genres = GetGenres()
                };
                return(View("New", viewModel));
            }
            var movieGenre = GetGenres().Find(g => g.Id == movie.GenreId);

            if (movie.Id == 0)
            {
                movie.DateAdded = DateTime.Now;
                movie.Genre     = movieGenre;
                _context.Movies.Add(movie);
            }
            else
            {
                var movieModel = _context.Movies.Single(m => m.Id == movie.Id);

                movieModel.Name          = movie.Name;
                movieModel.Genre         = movieGenre;
                movieModel.NumberInStock = movie.NumberInStock;
                movieModel.DateAdded     = DateTime.Now;
                movieModel.ReleaseDate   = movie.ReleaseDate;
                movieModel.GenreId       = movie.GenreId;
            }

            _context.SaveChanges();


            return(RedirectToAction("Index"));
        }
        public ActionResult Save(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieFormModel(movie)
                {
                    GenreTypes = _context.GenreTypes.ToList()
                };
                return(View("MovieForm", viewModel));
            }

            if (movie.Id == 0)
            {
                movie.NumberAvailable = movie.InStock;
                _context.Movies.Add(movie);
            }
            else

            {
                var movieInDb = _context.Movies.Single(c => c.Id == movie.Id);
                movieInDb.Name            = movie.Name;
                movieInDb.Genre           = movie.Genre;
                movieInDb.DateAdded       = movie.DateAdded;
                movieInDb.ReleaseDate     = movie.ReleaseDate;
                movieInDb.ReleaseDate     = movie.ReleaseDate;
                movieInDb.InStock         = movie.InStock;
                movieInDb.NumberAvailable = movie.InStock;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Movies"));
        }
        public ActionResult New(int?id)
        {
            MovieFormModel movieModel = null;

            if (id == null)
            {
                movieModel = new MovieFormModel()
                {
                    Genres = GetGenres()
                };
                ViewBag.Header = "New Movie";
            }
            else
            {
                Movie movie = _context.Movies.Find(id);
                movieModel = new MovieFormModel(movie)
                {
                    Genres = GetGenres()
                };
                ViewBag.Header = "Edit Movie";
            }


            return(View(movieModel));
        }
Beispiel #4
0
        public IActionResult Movies_Form(MovieFormModel movieFormModel)
        {
            if (movieFormModel.Title != "Independence Day")
            {
                TempModel.AddMovie(movieFormModel);
            }

            return(View());
        }
Beispiel #5
0
        public ActionResult New()
        {
            var genres = db.Genre.ToList();

            var viewModel = new MovieFormModel
            {
                Genres = genres
            };

            return(View("MovieForm", viewModel));
        }
        public ActionResult New()
        {
            var genreTypes = _context.GenreTypes.ToList();


            var viewModel = new MovieFormModel()
            {
                GenreTypes = genreTypes
            };

            return(View("MovieForm", viewModel));
        }
        public ActionResult Edit(int id)
        {
            var movie = _context.Movies.SingleOrDefault(c => c.Id == id);

            if (movie == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new MovieFormModel(movie)
            {
                GenreTypes = _context.GenreTypes.ToList()
            };

            return(View("MovieForm", viewModel));
        }
Beispiel #8
0
        public ActionResult Edit(int id)
        {
            //var movies = GetMovies();
            var movie = db.Movie.Include(m => m.Genre).SingleOrDefault(c => c.Id == id);

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


            var viewModel = new MovieFormModel
            {
                movie  = movie,
                Genres = db.Genre.ToList()
            };

            return(View("MovieForm", viewModel));
        }
 public IActionResult MovieForm(MovieFormModel appResponse)
 {
     TempStorage.AddMovie(appResponse);
     Debug.WriteLine("Title: " + appResponse.title);
     return(View("Confirmation", appResponse));
 }