public void InsertOrUpdate(Photo photo) { if (photo.PhotoId == default(int)) { // New entity context.Photos.Add(photo); } else { // Existing entity context.Entry(photo).State = EntityState.Modified; } }
public ActionResult Create(Photo photo) { if (ModelState.IsValid) { photoRepository.InsertOrUpdate(photo); photoRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleAlbums = albumRepository.All; return View(); } }