public ActionResult FollowUpSurvey([Bind(Include = "SurveyID,QuestionNum,Questions,Answer")] QuestionViewModel model) { OSUSurvey survey = db.Surveys.Find(model.SurveyID); if (survey != null) { while (model.QuestionNum < (model.Questions.Count() - 1)) { Question currentQuestion = model.Questions[model.QuestionNum]; currentQuestion.AskedFlag = true; currentQuestion.CurrentQuestionFlag = false; int currentIndex = model.Questions.IndexOf(currentQuestion); model.Questions[model.QuestionNum].CurrentQuestionFlag = false; model.Questions[model.QuestionNum].AskedFlag = true; model.QuestionNum = model.QuestionNum + 1; model.Questions[model.QuestionNum].CurrentQuestionFlag = true; Question nextQuestion = model.Questions[model.QuestionNum]; nextQuestion.CurrentQuestionFlag = true; OSUAnswer answer = new OSUAnswer(); answer.AnswerFlag = model.Answer.AnswerFlag; answer.AnswerValue = model.Answer.AnswerValue; answer.SurveyID = model.Answer.SurveyID; answer.QuestionID = model.Answer.QuestionID; //answer.QuestionRoundNum = 2; db.Answers.Add(answer); db.SaveChanges(); OSUAnswer newAnswer = new OSUAnswer(); newAnswer.AnswerFlag = null; newAnswer.SurveyID = survey.SurveyID; newAnswer.QuestionID = nextQuestion.QuestionID; //newAnswer.QuestionRoundNum = 2; model.Answer = newAnswer; ModelState.Clear(); return(View(model)); } OSUAnswer finalAnswer = new OSUAnswer(); finalAnswer.AnswerFlag = model.Answer.AnswerFlag; finalAnswer.AnswerValue = model.Answer.AnswerValue; finalAnswer.SurveyID = model.Answer.SurveyID; finalAnswer.QuestionID = model.Answer.QuestionID; //finalAnswer.QuestionRoundNum = 2; db.Answers.Add(finalAnswer); db.SaveChanges(); return(RedirectToAction("Enjoyment", new { id = model.SurveyID })); } return(View(model)); }
public ActionResult Thoughts(int?id) { OSUSurvey survey = db.Surveys.Find(id); SettingSet settings = db.SettingSets.Find(survey.SettingsID); EnjoymentViewModel model = new EnjoymentViewModel(); List <Question> questions = db.Questions.Where(x => x.QuestionRoundNum == 4 && x.SettingSetID == settings.SettingSetID).OrderBy(x => x.GroupQuestionNumber).ToList(); List <Question> ouQuestions = questions.Where(x => x.GroupQuestionNumber < 5).ToList(); List <Question> uoQuestions = questions.Where(x => x.GroupQuestionNumber > 4).ToList(); List <Question> thoughtsQuestions = new List <Question>(); int k = random.Next(0, 2); if (k == 0) { thoughtsQuestions.AddRange(ouQuestions); thoughtsQuestions.AddRange(uoQuestions); } else { thoughtsQuestions.AddRange(uoQuestions); thoughtsQuestions.AddRange(ouQuestions); } List <OSUAnswer> answers = new List <OSUAnswer>(); foreach (Question question in thoughtsQuestions) { OSUAnswer answer = new OSUAnswer(); answer.SurveyID = survey.SurveyID; //answer.QuestionRoundNum = 4; answer.QuestionID = question.QuestionID; answer.SurveyID = survey.SurveyID; answers.Add(answer); } model.SurveyID = survey.SurveyID; model.Questions = thoughtsQuestions; model.Answers = answers; return(View(model)); }
public ActionResult FollowUpSurvey(int?id) { QuestionViewModel model = new QuestionViewModel(); OSUSurvey survey = db.Surveys.Find(id); if (survey != null) { SettingSet settings = db.SettingSets.Find(survey.SettingsID); List <Question> questions = db.Questions.Where(x => x.SettingSetID == settings.SettingSetID && x.QuestionRoundNum == 2).ToList(); List <Question> shuffledQuestions = new List <Question>(); int n = questions.Count(); while (n >= 1) { n--; int k = random.Next(n + 1); Question question = questions[k]; questions.Remove(question); shuffledQuestions.Add(question); } model.Questions = shuffledQuestions; model.QuestionNum = 0; model.Questions[0].CurrentQuestionFlag = true; OSUAnswer answer = new OSUAnswer(); answer.SurveyID = survey.SurveyID; answer.QuestionID = model.Questions[0].QuestionID; //answer.QuestionRoundNum = 2; model.Answer = answer; model.SurveyID = survey.SurveyID; } return(View(model)); }
public ActionResult Final(int?id) { OSUSurvey survey = db.Surveys.Find(id); SettingSet settings = db.SettingSets.Find(survey.SettingsID); EnjoymentViewModel model = new EnjoymentViewModel(); List <Question> questions = db.Questions.Where(x => x.QuestionRoundNum == 5 && x.SettingSetID == settings.SettingSetID).OrderBy(x => x.GroupQuestionNumber).ToList(); List <OSUAnswer> answers = new List <OSUAnswer>(); List <Question> shuffledQuestions = new List <Question>(); int n = questions.Count(); while (n >= 1) { n--; int k = random.Next(n + 1); Question question = questions[k]; questions.Remove(question); shuffledQuestions.Add(question); } foreach (Question question in shuffledQuestions) { OSUAnswer answer = new OSUAnswer(); answer.SurveyID = survey.SurveyID; //answer.QuestionRoundNum = 5; answer.QuestionID = question.QuestionID; answer.SurveyID = survey.SurveyID; answers.Add(answer); } model.SurveyID = survey.SurveyID; model.Questions = shuffledQuestions; model.Answers = answers; return(View(model)); }