public ActionResult Show(int? id,string sort) { ViewQuestion vq=new ViewQuestion(); int qid = id ?? 0; ViewBag.CurrentUser = GetUser(); using (club = new ClubEntities()) { vq = club.ViewQuestions.Where(q => q.Id == qid).FirstOrDefault(); var question = club.Questions.Where(q => q.Id == qid).FirstOrDefault(); if (question != null) { question.Views += 1; } club.SaveChanges(); ViewBag.AnswerCount = club.Answers.Where(a => a.QId == qid).Count(); ViewBag.AnswerVote = club.AnswerVotes.Where(a => a.QId == qid).ToList<AnswerVote>(); switch(sort){ case "time": ViewBag.ViewAnswers = GetAnswerList(club, q => q.QId == qid,q=>q.Id,0); break; case "vote": ViewBag.ViewAnswers = GetAnswerList(club, q => q.QId == qid, q => q.Agree, 0); break; default: ViewBag.ViewAnswers = GetAnswerList(club, q => q.QId == qid,q=>q.Id,0); break; } if (vq == null) return Redirect("/error/notfound"); ViewBag.Title = vq.Title; ViewBag.OtherQuestions = club.Questions.Where(q => q.UserId == vq.UserId&&q.Id!=vq.Id).Take(6).ToList<Question>(); } return View(vq); }
public ActionResult Show(int? id) { tId = id ?? 0; using (club = new ClubEntities()) { viewQuestion = club.ViewQuestions.Where(v => v.Id == tId).FirstOrDefault(); } if (viewQuestion == null) return RedirectToAction("notfound","error"); return View(viewQuestion); }