Beispiel #1
0
 public ActionResult AddMovie(movie movie)
 {
     if (!ModelState.IsValid)
     {
         var Errmovie = new AddMoviesViewModel
         {
             Movie  = movie,
             Genres = _context.Genres.ToList(),
         };
         return(View("New", Errmovie));
     }
     if (movie.id == 0)
     {
         movie.dateAdded = DateTime.Now;
         _context.movies.Add(movie);
     }
     else
     {
         var MovieInDb = _context.movies.Single(m => m.id == movie.id);
         MovieInDb.dateReleased   = movie.dateReleased;
         MovieInDb.name           = movie.name;
         MovieInDb.genreTypeId    = movie.genreTypeId;
         MovieInDb.stockAvailable = movie.stockAvailable;
     }
     _context.SaveChanges();
     return(RedirectToAction("movies"));
 }
Beispiel #2
0
        public ActionResult New()
        {
            var movie = new AddMoviesViewModel
            {
                Genres = _context.Genres.ToList(),
            };

            return(View(movie));
        }
Beispiel #3
0
        public ActionResult Edit(int id)
        {
            var movie = new AddMoviesViewModel
            {
                Movie  = _context.movies.Single(m => m.id == id),
                Genres = _context.Genres.ToList(),
            };

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