public ActionResult QuestionDetails(Guid id, string errorMessage = null) { var context = new StackOverflowContext(); var context2 = new StackOverflowContext(); var question = context.Questions.Find(id); QuestionDetailsModel details = new QuestionDetailsModel(); details.Description = question.Description; details.Title = question.Title; details.Score = question.Votes; details.QuestionId = id; details.ErrorMessage = errorMessage; HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie != null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); Guid ownerId = Guid.Parse(ticket.Name); details.UserHasVoted = (context2.Votes.FirstOrDefault( x => x.AccountReference == ownerId && x.ReferenceToQuestionOrAnswer == id) != null); } else { details.UserHasVoted = false; } ++(question.NumberOfViews); Session["CurrentQ"] = question.Id; context.SaveChanges(); ViewData["qId"] = id; return(View(details)); }
public IActionResult Details(int?id) { if (id != null && this.questionsService.Exists(id.Value)) { QuestionDetailsModel model = this.questionsService.GetDetails(id.Value); this.ViewData["stared"] = this.questionsService.UserHasStared(id.Value, this.User.GetUserId()); model.Content = this.htmlSanitizer.Sanitize(model.Content); model.SimilarTags = this.tagService.GetSimilarTags(model.Tags, 15); this.ViewData["youtubeKeyword"] = Uri.EscapeDataString(string.Join(" ", model.Tags)); return(View(model)); } return(BadRequest()); }