public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(movie);
        }
Exemplo n.º 2
0
        public ActionResult Delete(Movie movieToDelete)
        {
            var originalMovie = (from m in _db.Movies
                                 where m.Id == movieToDelete.Id
                                 select m).First();

            if (!ModelState.IsValid)
                return View(originalMovie);

            _db.Movies.Remove(originalMovie);
            _db.SaveChanges();
            return RedirectToAction("Index");
        }
 private static void UpdateEntityValues(Movie movie, Movie foundMovie)
 {
     foundMovie.Title = movie.Title;
     foundMovie.Studio = movie.Studio;
     foundMovie.StudioAddress = movie.StudioAddress;
     foundMovie.Year = movie.Year;
     foundMovie.Director = movie.Director;
     foundMovie.LeadFemaleActor = movie.LeadFemaleActor;
     foundMovie.LeadMaleActor = movie.LeadMaleActor;
 }
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         //db.Entry(movie).State = EntityState.Modified;
         var foundMovie = db.Movies.Single(x => x.Id == movie.Id);
         UpdateEntityValues(movie, foundMovie);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(movie);
 }
Exemplo n.º 5
0
        public ActionResult Edit(Movie movieToEdit)
        {
            var originalMovie = (from m in _db.Movies
                                    where m.Id == movieToEdit.Id
                                    select m).First();

            if (!ModelState.IsValid)
                return View(originalMovie);

            _db.Entry(originalMovie).CurrentValues.SetValues(movieToEdit);
            _db.SaveChanges();
            return RedirectToAction("Index");
        }