public ActionResult Create(Album album) { if (ModelState.IsValid) { albumRepository.InsertOrUpdate(album); albumRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Album album) { if (album.AlbumId == default(int)) { // New entity context.Albums.Add(album); } else { // Existing entity context.Entry(album).State = EntityState.Modified; } }