public ActionResult Question(long id) { var Question = db.Question.Find(id); var User = db.User.Find(Int32.Parse(Request.Cookies["user_active"].Value)); var answer = new Answer { Question = Question, User = User, QuestionID = Int32.Parse(Question.ID.ToString()), UserID = Int32.Parse(User.ID.ToString()) }; return View(answer); }
public ActionResult Answer([Bind(Include = "ID,QuestionID,UserID,Response,Date")] Answer answer) { if (ModelState.IsValid) { db.Answer.Add(answer); db.SaveChanges(); var current_question = db.Question.Find(answer.QuestionID); var Question = GetNextQuestion(answer.QuestionID, current_question.Order); if (Question != null) { var User = db.User.Find(Int32.Parse(Request.Cookies["user_active"].Value)); var next_question = new Answer { UserID = User.ID, Date = answer.Date, Question = Question, QuestionID = Int32.Parse(Question.ID.ToString()), User = User, Response = false }; return View(next_question); } else { return RedirectToAction("Index"); } } return View(answer); }