public ActionResult Create(Response response) { if (ModelState.IsValid) { responseRepository.InsertOrUpdate(response); responseRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Response response) { if (response.Id == default(int)) { // New entity context.Responses.Add(response); } else { // Existing entity context.Responses.Attach(response); context.Entry(response).State = EntityState.Modified; } }