Advertisement
Guest User

c#

a guest
Jul 31st, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1.         public ActionResult TakeQuiz(int id = 0)
  2.         {
  3.             QuizModel model = db.Quizzes.Single(m => m.ID == id);
  4.  
  5.             List<QuestionAnswer> qas = new List<QuestionAnswer>();
  6.  
  7.             ViewBag.Questions = (from entry in db.Questions.ToList() where entry.QuizID == id orderby entry.Question ascending select entry);
  8.  
  9.             foreach (QuestionModel qm in ViewBag.Questions)
  10.             {
  11.                 QuestionAnswer qa = new QuestionAnswer();
  12.                 qa.Question = qm;
  13.                 qa.Answers = (from entry in db.Answers.ToList() where entry.QuestionID == qm.ID orderby entry.Answer ascending select entry).ToList();
  14.  
  15.                 qas.Add(qa);
  16.             }
  17.  
  18.             ViewBag.QAs = qas;
  19.            
  20.             return View(model);
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement