public void InsertOrUpdate(Comment comment) { if (comment.CommentId == default(System.Guid)) { // New entity comment.CommentId = Guid.NewGuid(); context.Comment.Add(comment); } else { // Existing entity context.Entry(comment).State = EntityState.Modified; } }
public ActionResult Create(Comment comment) { if (ModelState.IsValid) { commentRepository.InsertOrUpdate(comment); commentRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleTask = taskRepository.All; ViewBag.PossibleUser = userRepository.All; return View(); } }