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