// // GET: /Topic/Details/5 public ActionResult Details(Guid?id = null) { if (!id.HasValue) { return(HttpNotFound()); } ContentTopic contentTopic = db.ContentTopics.Include(c => c.ContentThread) .Include(c => c.MemberUser) .Include(c => c.ContentComments) .Where(c => c.Id == id.Value).SingleOrDefault(); if (contentTopic == null) { return(HttpNotFound()); } var viewModel = new TopicCommentsViewModel() { Topic = contentTopic }; viewModel.Post = contentTopic.ContentComments.SingleOrDefault(x => x.Id == viewModel.Topic.FirstCommentId); viewModel.Comments = contentTopic.ContentComments.Where(x => x.Id != viewModel.Topic.FirstCommentId) .OrderBy(x => x.CreateTime) .ToList(); return(View(viewModel)); }
// // GET: /Topic/Edit/5 public ActionResult Edit(Guid?id = null) { if (!id.HasValue) { return(HttpNotFound()); } ContentTopic contentTopic = db.ContentTopics.Include(c => c.ContentThread) .Include(c => c.MemberUser) .Include(c => c.ContentComments) .Where(c => c.Id == id.Value).SingleOrDefault(); if (contentTopic == null) { return(HttpNotFound()); } var viewModel = new TopicCommentsViewModel() { Topic = contentTopic }; viewModel.Post = contentTopic.ContentComments.SingleOrDefault(x => x.Id == viewModel.Topic.FirstCommentId); viewModel.Comments = contentTopic.ContentComments.Where(x => x.Id != viewModel.Topic.FirstCommentId).ToList(); ViewBag.Threads = new SelectList(db.ContentThreads, "Id", "Name", viewModel.Topic.ThreadId); ViewBag.Users = new SelectList(db.MemberUsers, "Id", "UserName", viewModel.Topic.UserId); return(View(viewModel)); }
public ActionResult Edit(TopicCommentsViewModel viewModel) { var post = db.ContentComments.Single(x => x.Id == viewModel.Topic.FirstCommentId); post.Content = viewModel.Post.Content; post.OriginalContent = viewModel.Post.OriginalContent; viewModel.Post = post; if (ModelState.IsValid) { db.Entry(viewModel.Topic).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Topic.ThreadId = new SelectList(db.ContentThreads, "Id", "Name", viewModel.Topic.ThreadId); ViewBag.Topic.UserId = new SelectList(db.MemberUsers, "Id", "UserName", viewModel.Topic.UserId); return(View(viewModel)); }