public void InsertOrUpdate(Comment comment) { if (comment.ID == default(int)) { // New entity context.Comments.Add(comment); } else { // Existing entity context.Entry(comment).State = (System.Data.Entity.EntityState) EntityState.Modified; } }
public ActionResult Create(Comment comment) { if (ModelState.IsValid) { commentRepository.InsertOrUpdate(comment); commentRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleArticles = articleRepository.All; return View(); } }