public ActionResult Create(Thread thread,string threadContent) { if (String.IsNullOrWhiteSpace(threadContent)) { ModelState.AddModelError("threadContent","请输入内容"); } if (ModelState.IsValid) { thread.PostDate = DateTime.Now; thread.LatestReplyDate = DateTime.Now; thread.AuthorUserName = User.Identity.Name; Reply tempReply = new Reply{ Thread = thread, Number = 1, Date = DateTime.Now, AuthorUserName = User.Identity.Name, Content = threadContent}; unitOfWork.Replies.Add(tempReply); thread.Replies.Add(tempReply); unitOfWork.Threads.Add(thread); unitOfWork.SaveChanges(); return RedirectToAction("Index"); } return View(thread); }
public ActionResult Details(int id, string reply) { Thread thread = unitOfWork.Threads.Find(id); if (String.IsNullOrWhiteSpace(reply)) { ModelState.AddModelError("replyError", "请输入内容"); return Json(new { success = false, msg = "请输入内容" }); } if (ModelState.IsValid) { Reply tempReply = new Reply { Content = reply, AuthorUserName = User.Identity.Name, Date = DateTime.Now, Number = thread.Replies.Count+1, Thread = thread }; unitOfWork.Replies.Add(tempReply); thread.Replies.Add(tempReply); unitOfWork.SaveChanges(); } return Json(new { success = true, msg = "" }); }