public ActionResult StartSyncSession(String load) { if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if ((int)Session["user_type"] < User_Type.POLL_USER) { return RedirectToAction("Invalid", "Home"); } int userid = (int)Session["uid"]; int pollid = (int)Session["syncPollId"]; int sessionid = (int)Session["syncSessionId"]; Session["numOfPossibleAnswers"] = 2; int currentQuestionid = (int)Session["syncCurrentQuestionId"]; Boolean isOpen = true; int uid = (int)Session["uid"]; string message = Request["msg"].ToString(); if (!message.Equals("")) { messageModel msgModel = new messageModel(); msgModel.sendFeedback(message, uid, pollid, currentQuestionid); } PollAndQuestions pollAndQuestionModel = new PollAndQuestions(); pollAndQuestionModel.sessionData = new pollModel().displaySessionDetails(sessionid); List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid); pollAndQuestionModel.questionData = new questionModel().getQuestion(currentQuestionid); pollAndQuestionModel.answerData = new answerModel().displayAnswers(currentQuestionid); if (pollAndQuestionModel.questionData.questiontype >= 3) { // If this is a normal MCQ if (pollAndQuestionModel.questionData.questiontype < 6) { int selectedAnswer = Convert.ToInt32(Request["MCQAnswer"]); if (selectedAnswer != 0) { new responseModel().createMCQResponse(userid, selectedAnswer, sessionid); } else { String error = "webpollingError" + "," + "Please provide your answer(s)"; TempData["webpollingError"] = error; return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid }); } } else if (pollAndQuestionModel.questionData.questiontype == 6) { String selectedAnswer = Request["RankingAnswerList"]; Boolean redundant = isRedundant(selectedAnswer); Boolean empty = isEmpty(selectedAnswer); if (!redundant && !empty) { String[] answers = selectedAnswer.Split(','); for (int i = 0; i < answers.Count(); i++) { int preferencenumber = i; try { new responseModel().createRankingResponse(userid, Convert.ToInt32(answers[i]), sessionid, preferencenumber + 1); } catch (Exception e) { throw (e); } } } // If any of the inputs are the same value else if (redundant && !empty) { String error = "webpollingError" + "," + "Each answer has to be unique"; TempData["webpollingError"] = error; return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid }); } else { String error = "webpollingError" + "," + "Please provide your answer(s)"; TempData["webpollingError"] = error; return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid }); } } } else if (pollAndQuestionModel.questionData.questiontype <= 2) { Boolean isValid = true; String selectedAnswer = Request["ShortQuestionAnswer"]; if (selectedAnswer == "" || selectedAnswer == null) { isValid = false; String error = "webpollingError" + "," + "Please provide your answer(s)"; TempData["webpollingError"] = error; return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid }); } else if (pollAndQuestionModel.questionData.questiontype == 1 && !Regex.IsMatch(selectedAnswer, @"^\d+$")) { isValid = false; String error = "webpollingError" + "," + "Only numeric answer is allowed"; Session["shortAnswer"] = ""; TempData["webpollingError"] = error; return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid }); } else if (pollAndQuestionModel.questionData.questiontype == 2 && Regex.IsMatch(selectedAnswer, @"^\d+$")) { isValid = false; String error = "webpollingError" + "," + "Only alphanumeric answer is not allowed"; Session["shortAnswer"] = ""; TempData["webpollingError"] = error; return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid }); } if (isValid) { AnswerShortAnswerQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentQuestionid); } else { return RedirectToAction("StartSyncSession", new { sessionid = sessionid ,pollid = pollid}); } } while (isOpen) { int databaseCurrentQuestion = new pollModel().displaySessionDetails(sessionid)[0].currentquestion; // If the poll is closed by Poll Master, redirect them to a thank you page. if (currentQuestionid != databaseCurrentQuestion) { if (databaseCurrentQuestion == 0) { isOpen = false; } //else if (databaseCurrentQuestion == -1) //{ // Session["showGraph"] = true; // //Response.Write("<SCRIPT LANGUAGE=\"JavaScript\">\n"); // //Response.Write("window.open( \"\/PopUp\/Popup.html\", \"\", \"width=300, height=100\")"); // //Response.Write("<\/script>"); //} else { Session["showGraph"] = false; pollAndQuestionModel.sessionData = new pollModel().displaySessionDetails(sessionid); pollAndQuestionModel.questionData = new questionModel().getQuestion(databaseCurrentQuestion); List<answerModel> temp = new answerModel().displayAnswers(databaseCurrentQuestion); pollAndQuestionModel.answerData = temp; List<answerModel> sorted = pollAndQuestionModel.answerData; Session["syncCurrentQuestionId"] = databaseCurrentQuestion; if (pollAndQuestionModel.questionData.questiontype == 6) { Session["numOfPossibleAnswers"] = pollAndQuestionModel.questionData.numberofresponses; buildPlainSelectList(sorted); } isOpen = new pollModel().isOpen(sessionid); return View(pollAndQuestionModel); } } else if (currentQuestionid == databaseCurrentQuestion) { isOpen = new pollModel().isOpen(sessionid); // This doesnt get displayed - 8 October } if (!isOpen) { break; } else { System.Threading.Thread.Sleep(200); } //return View(pollAndQuestionModel); } // When the session is closed, redirect the user somewhere *sighhhhhhh return RedirectToAction("ConfirmationPage", new { sessionid = sessionid, pollid = pollid }); }
public ActionResult StartAsyncSession(String button) { if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if ((int)Session["user_type"] < User_Type.POLL_USER) { return RedirectToAction("Invalid", "Home"); } PollAndQuestions pollAndQuestionModel = new PollAndQuestions(); int sessionid = (int)Session["currentWebpollingSessionid"]; int pollid = (int)Session["currentWebpollingPollid"]; int questnum = (int)Session["currentQuestionNumber"]; List<questionModel> allquestion = (List<questionModel>)Session["AllQuestion"]; int currentquestion = allquestion[questnum].questionid; int uid = (int)Session["uid"]; string message = Request["msg"].ToString(); if (!message.Equals("")) { messageModel msgModel = new messageModel(); msgModel.sendFeedback(message, uid, pollid, currentquestion); } Session["selectedAnswer"] = ""; // if the user is currently answering an MCQ if (allquestion[questnum].questiontype >= 3){ // If this is a normal MCQ if (allquestion[questnum].questiontype < 6) { int selectedAnswer = Convert.ToInt32(Request["MCQAnswer"]); if (selectedAnswer != null) { AnswerMultipleChoiceQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentquestion); List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid); if (button == "Previous Question") { Session["currentQuestionNumber"] = questnum - 1; int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid; setNextAnswer(questnum + 1, nextquestion, sessionid, (int)Session["uid"]); } // if its the last question, then submit/ update answer but stay on the same question else if (button == "Submit Last Answer") { Session["currentQuestionNumber"] = questnum; Session["selectedAnswer"] = Request["MCQAnswer"]; Session["completed"] = "Thank you, you have completed all of the questions in this session."; } // its the next button else { Session["currentQuestionNumber"] = questnum + 1; int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid; setNextAnswer(questnum - 1, nextquestion, sessionid, (int)Session["uid"]); } } // if the user hasnt answered anything, then display error and ask em to answer it NAO else { String error = "webpollingError" + "," + "Please provide your answer(s)"; TempData["webpollingError"] = error; } } // Else, it must be a ranking MCQ where a number of answers allowed is > 1 else if (allquestion[questnum].questiontype == 6) { String selectedAnswer = Request["RankingAnswerList"]; Boolean redundant = isRedundant(selectedAnswer); Boolean empty = isEmpty(selectedAnswer); if (!redundant && !empty) { AnswerRankingQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentquestion); List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid); if (button == "Previous Question") { Session["currentQuestionNumber"] = questnum - 1; int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid; setNextAnswer(questnum + 1, nextquestion, sessionid, (int)Session["uid"]); } // if its the last question, then submit/ update answer but stay on the same question else if (button == "Submit Last Answer") { Session["currentQuestionNumber"] = questnum; Session["selectedAnswer"] = Request["MCQAnswer"]; Session["completed"] = "Thank you, you have completed all of the questions in this session."; } // its the next button else { Session["currentQuestionNumber"] = questnum + 1; int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid; setNextAnswer(questnum - 1, nextquestion, sessionid, (int)Session["uid"]); } } // If any of the inputs are the same value else if (redundant && !empty) { String error = "webpollingError" + "," + "Each answer has to be unique"; TempData["webpollingError"] = error; } else { String error = "webpollingError" + "," + "Please provide your answer(s)"; TempData["webpollingError"] = error; } } } // Then the the user is currently answering a short answer question type else if (allquestion[questnum].questiontype <=2 ) { Boolean isValid = true; String selectedAnswer = Request["ShortQuestionAnswer"]; // If its short answer numeric type only if (selectedAnswer == "") { isValid = false; String error = "webpollingError" + "," + "Please provide your answer(s)"; TempData["webpollingError"] = error; } else if (allquestion[questnum].questiontype == 1 && !Regex.IsMatch(selectedAnswer, @"^\d+$")) { isValid = false; String error = "webpollingError" + "," + "Only numeric answer is allowed"; Session["shortAnswer"] = ""; TempData["webpollingError"] = error; } else if (allquestion[questnum].questiontype == 2 && Regex.IsMatch(selectedAnswer, @"^\d+$")) { isValid = false; String error = "webpollingError" + "," + "Only alphanumeric answer is not allowed"; Session["shortAnswer"] = ""; TempData["webpollingError"] = error; } if (isValid) { AnswerShortAnswerQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentquestion); List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid); if (button == "Previous Question") { Session["currentQuestionNumber"] = questnum - 1; int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid; setNextAnswer(questnum + 1, nextquestion, sessionid, (int)Session["uid"]); } // if its the last question, then submit/ update answer but stay on the same question else if (button == "Submit Last Answer") { Session["currentQuestionNumber"] = questnum; Session["shortAnswer"] = Request["ShortQuestionAnswer"]; Session["completed"] = "Thank you, you have completed all of the questions in this session."; } // its the next button else { Session["currentQuestionNumber"] = questnum + 1; int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid; setNextAnswer(questnum - 1, nextquestion, sessionid, (int)Session["uid"]); } } } return RedirectToAction("StartAsyncSession", new { sessionid = sessionid, pollid = pollid }); }
public ActionResult StartSyncSession(int sessionid, int pollid) { if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if ((int)Session["user_type"] < User_Type.POLL_USER) { return RedirectToAction("Invalid", "Home"); } if (TempData["webpollingError"] != null) { String[] error = TempData["webpollingError"].ToString().Split(','); ModelState.AddModelError(error[0], error[1]); } Session["syncSessionId"] = sessionid; Session["syncPollId"] = pollid; int userid = (int)Session["uid"]; pollModel currentQuestion = new pollModel().displaySessionDetails(sessionid)[0]; int currentQuestionid = currentQuestion.currentquestion; Session["syncCurrentQuestionId"] = currentQuestionid; PollAndQuestions pollAndQuestionModel = new PollAndQuestions(); pollAndQuestionModel.sessionData = new pollModel().displaySessionDetails(sessionid); List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid); pollAndQuestionModel.questionData = new questionModel().getQuestion(currentQuestionid); pollAndQuestionModel.answerData = new answerModel().displayAnswers(currentQuestionid); List<answerModel> sorted = pollAndQuestionModel.answerData; if (pollAndQuestionModel.questionData.questiontype == 6) { Session["numOfPossibleAnswers"] = pollAndQuestionModel.questionData.numberofresponses; buildPlainSelectList(sorted); } return View(pollAndQuestionModel); }
public ActionResult StartAsyncSession(int sessionid, int pollid) { if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if ((int)Session["user_type"] < User_Type.POLL_USER) { return RedirectToAction("Invalid", "Home"); } int questnum = 0; if (Session["currentQuestionNumber"] == null || (int)Session["currentWebpollingSessionid"] != sessionid) { Session["currentQuestionNumber"] = 0; Session["completed"] = ""; questnum = (int)Session["currentQuestionNumber"]; } else { questnum = (int)Session["currentQuestionNumber"]; } if (TempData["webpollingError"] != null) { String[] error = TempData["webpollingError"].ToString().Split(','); ModelState.AddModelError(error[0], error[1]); } PollAndQuestions pollAndQuestionModel = new PollAndQuestions(); pollAndQuestionModel.sessionData = new pollModel().displaySessionDetails(sessionid); List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid); Session["currentWebpollingSessionid"] = sessionid; Session["currentWebpollingPollid"] = pollid; pollAndQuestionModel.questionData = new questionModel().getQuestion(tempList[questnum].questionid); Session["AllQuestion"] = tempList; //if its the last question, then let the view know so that the next button could be replaced with submit last answer Session["endOfQuestion"] = false; if (tempList.Count() == questnum+1) { Session["endOfQuestion"] = true; } Session["currentQuestionNumber"] = questnum; List<answerModel> unsorted = new answerModel().getPollAnswers(pollid); List<answerModel> s = new List<answerModel>(); List<int> questionCheck = new List<int>(); List<questionModel> answeredQuestions = new questionModel().GetAnsweredMCQQuestions(sessionid, (int)Session["uid"]); // Get a set of answer list for this question foreach (var answer in unsorted) { if (pollAndQuestionModel.questionData.questionid == answer.questionid && !questionCheck.Contains(pollAndQuestionModel.questionData.questionid)) { //sorted.Add(new answerModel().displayAnswers(pollAndQuestionModel.questionData.questionid)); s = new answerModel().displayAnswers(pollAndQuestionModel.questionData.questionid); questionCheck.Add(pollAndQuestionModel.questionData.questionid); } } pollAndQuestionModel.answerData = s; List<int?> selected = new List<int?>(); // To set the first question's radio button to user's previous answer if he's answered it before foreach (var answeredquestion in answeredQuestions) { selected = new responseModel().getRankingAnswerIds(sessionid, (int)Session["uid"], pollAndQuestionModel.questionData.questionid); foreach (var a in s) { if (answeredquestion.answer == a.answer) { Session["selectedAnswer"] = answeredquestion.answer; } } } if (pollAndQuestionModel.questionData.questiontype == 6) { ViewData["numOfPossibleAnswers"] = pollAndQuestionModel.questionData.numberofresponses; buildSelectList(s, selected); } return View(pollAndQuestionModel); }