public ActionResult Edit(Trip trip) { if (ModelState.IsValid) { tripRepository.InsertOrUpdate(trip); tripRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Trip trip) { if (trip.Id == default(int)) { // New entity context.Trips.Add(trip); } else { // Existing entity context.Entry(trip).State = EntityState.Modified; } }