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 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 }); }
// // GET: /Session/Delete/5 public ActionResult Delete(int sessionid) { if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if ((int)Session["user_type"] < User_Type.POLL_ADMINISTRATOR) { return RedirectToAction("Invalid", "Home"); } pollModel poll = new pollModel(sessionid, 1); poll.deleteSession(); return RedirectToAction("Index", "Poll"); }