public async Task <IActionResult> VerifyAnswer(int ansId, int questionId) { var user = await OnGetSesstion(); UserQuestion question = _context.UserQuestion.Where(x => x.UserQuestionId == questionId && x.UserId == user).SingleOrDefault(); UserQAnswer answer = _context.UserQAnswer.Where(y => y.UserQAnswerId == ansId).SingleOrDefault(); if (question != null && answer != null) { question.HasVerifiedAns = true; answer.IsVerified = true; _context.SaveChanges(); TempData["Msg"] = "Answer has been verified!"; TempData["Color"] = "success"; } return(RedirectToAction($"QuestionDetail", new { id = questionId })); }
public async Task <IActionResult> PostAnswer(CommonViewModel vm) { if (ModelState.IsValid) { var user = await OnGetSesstion(); UserQAnswer userQAnswer = new UserQAnswer(); userQAnswer.Description = HttpUtility.HtmlEncode(vm.QAnswerViewModel.Description); userQAnswer.PostTime = DateTime.UtcNow; userQAnswer.UserId = user; userQAnswer.UserQuestionId = vm.QAnswerViewModel.QuestionId; _context.UserQAnswer.Add(userQAnswer); _context.SaveChanges(); return(RedirectToAction($"QuestionDetail", new { id = vm.QAnswerViewModel.QuestionId })); } return(View("Detail", vm.NewQuestionVM)); }