public ActionResult Create(Surface surface) { if (ModelState.IsValid) { surfaceRepository.InsertOrUpdate(surface); surfaceRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Surface surface) { if (surface.SurfaceId == default(int)) { // New entity context.Surfaces.Add(surface); } else { // Existing entity context.Entry(surface).State = EntityState.Modified; } }