public ActionResult Create(Survey survey) { if (ModelState.IsValid) { surveyRepository.InsertOrUpdate(survey); surveyRepository.Save(); return RedirectToAction("Index"); } return View(survey); }
public void InsertOrUpdate(Survey survey) { if (survey.Id == default(int)) { // New entity context.Surveys.Add(survey); } else { // Existing entity context.Entry(survey).State = EntityState.Modified; } }