public void InsertOrUpdate(Movie movie) { if (movie.ID == default(int)) { // New entity context.Movies.Add(movie); } else { // Existing entity context.Entry(movie).State = EntityState.Modified; } }
public ActionResult Create(Movie movie) { if (ModelState.IsValid) { movieRepository.InsertOrUpdate(movie); movieRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleDirectors = directorRepository.All; ViewBag.PossibleCountries = countryRepository.All; return View(); } }