コード例 #1
0
 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;
     }
 }
コード例 #2
0
 public ActionResult Create(Comment comment)
 {
     if (ModelState.IsValid) {
         commentRepository.InsertOrUpdate(comment);
         commentRepository.Save();
         return RedirectToAction("Index");
     } else {
         ViewBag.PossibleArticles = articleRepository.All;
         return View();
     }
 }