public async Task<ActionResult> GetQuestionnaire(Questionnaire questionnaire) { Questionnaire q = questionnaire; return View(); }
public async Task<ActionResult> GetQuestionnaire() { int id = 5; IEnumerable<QuestionAnswer> entities = await db.QuestionAnswers // TODO: Add Includes for reference and/or collection properties .ToListAsync(); Test testEntity = db.Tests.Where(x => x.TestId == id).FirstOrDefault(); // Id is hard coded right now, need to pass it in List<QuestionAnswer> QAList = new List<QuestionAnswer>(); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId01.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId02.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId03.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId04.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId05.Value).FirstOrDefault()); // 5 QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId06.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId07.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId08.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId09.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId10.Value).FirstOrDefault()); // 10 QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId11.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId12.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId13.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId14.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId15.Value).FirstOrDefault()); // 15 QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId16.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId17.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId18.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId19.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId20.Value).FirstOrDefault()); // 20 QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId21.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId22.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId23.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId24.Value).FirstOrDefault()); QAList.Add(db.QuestionAnswers.Where(x => x.QuestionAnswerId == testEntity.QaId25.Value).FirstOrDefault()); // 25 // enter remaining 20 questions here Questionnaire questionnaire = new Questionnaire(); foreach (var item in QAList) { if (item != null) { Question question = new Question(); question.type = item.QuestionType; question.Title = item.QuestionText; question.correctAnswer = item.CorrectAnswer; // 1-> 5 are 's' if (question.type == "M" || question.type == "m") { question.answerList.Add(new Answer(item.MC_AnswerText1, "1) ")); question.answerList.Add(new Answer(item.MC_AnswerText2, "2) ")); question.answerList.Add(new Answer(item.MC_AnswerText3, "3) ")); question.answerList.Add(new Answer(item.MC_AnswerText4, "4) ")); question.answerList.Add(new Answer(item.MC_AnswerText5, "5) ")); } else if (question.type == "T") { question.answerList.Add(new Answer(item.MC_AnswerText1, "1) true")); question.answerList.Add(new Answer(item.MC_AnswerText2, "2) false")); } else if (question.type == "W") { question.answerList.Add(new Answer(item.MC_AnswerText1, "")); } questionnaire.questionList.Add(question); } } return View(questionnaire); }