상속: System.Web.UI.Page
예제 #1
0
        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);
        }
예제 #2
0
        // Function to either create or update a MCQ of type 3, 4 and 5
        public void AnswerMultipleChoiceQuestion(int selectedAnswer, int sessionid, int userid, int currentquestionid)
        {
            List<questionModel> answeredQuestions = new questionModel().GetAnsweredMCQQuestions(sessionid, userid);

            questionModel answeredQuestion = new questionModel();

            foreach (var item in answeredQuestions)
            {
                if (item.questionid == currentquestionid)
                {
                    answeredQuestion = item;
                }
            }

            // If a question has been answered by this user before, then update that data
            if (answeredQuestion.question != null)
            {
                int responseId = new responseModel().getResponseId(sessionid, userid, answeredQuestion.answer);

                try
                {
                    new responseModel().updateMCQResponse(responseId, selectedAnswer);
                }
                catch (Exception e)
                {
                    throw (e);
                }
            }
            // else create a new row
            else
            {
                try
                {
                    new responseModel().createMCQResponse(userid, selectedAnswer, sessionid);
                }
                catch (Exception e)
                {
                    throw (e);
                }
            }
        }
예제 #3
0
        // Function to either create or update a MCQ of type 6, Ranking Question
        public void AnswerRankingQuestion(String selectedAnswer, int sessionid, int userid, int currentquestionid)
        {
            List<questionModel> answeredQuestions = new questionModel().GetAnsweredMCQQuestions(sessionid, userid);

            List<String> answeredQuestion = new List<String>();

            foreach (var item in answeredQuestions)
            {
                if (item.questionid == currentquestionid)
                {
                    answeredQuestion.Add(item.answer);
                }
            }

             String[] answers = selectedAnswer.Split(',');

            // If a question has been answered by this user before, then update that data
            if (answeredQuestion.Count() != 0)
            {

                for (int i = 0; i < answers.Count(); i++)
                {
                    int responseId = new responseModel().getResponseId(sessionid, userid, answeredQuestion[i]);
                    int preferencenumber = i;
                    try
                    {
                        new responseModel().updateRankingResponse(responseId, Convert.ToInt32(answers[i]), preferencenumber+1);
                    }
                    catch (Exception e)
                    {
                        throw (e);
                    }
                }

            }
            // else create a new row
            else
            {
                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);
                    }
                }
            }
        }