상속: System.Web.UI.Page
예제 #1
0
        public ActionResult Delete(int aid, int ahid)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_MASTER)
            {
                return RedirectToAction("Invalid", "Home");
            }

            new answerHistoryModel(ahid).deleteAnswerHistory();

            answerModel a = new answerModel();
            a = a.getAnswer(aid);
            return RedirectToAction("Index", "answerHistory", new { id = a.answerid, name = a.answer });
        }
예제 #2
0
        public ActionResult Revert(int answerid, String answer, int correct, String weight, string ansnum)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_MASTER)
            {
                return RedirectToAction("Invalid", "Home");
            }

            answerModel a = new answerModel();
            a = a.getAnswer(answerid);

            /* Create a record of the old answer in the Answer History table */
            new answerHistoryModel(answerid).createAnswerHistory(a.answerid, a.answer, a.correct, a.weight, a.ansnum);

            /* Update the answer*/
            a.updateAnswer(answerid, answer, correct, int.Parse(weight), int.Parse(ansnum));
            a = a.getAnswer(answerid);
            return RedirectToAction("Index", "answerHistory", new { id = a.answerid, name = a.answer } );
        }
예제 #3
0
        public ActionResult SevenOpinionScale(String answer, int correct, String weight, int questionid, String ansnum, String answer1, int correct1, String weight1, String ansnum1,
            String answer2, int correct2, String weight2, String ansnum2, String answer3, int correct3, String weight3, String ansnum3,
            String answer4, int correct4, String weight4, String ansnum4,
            String answer5, int correct5, String weight5, String ansnum5,
            String answer6, int correct6, String weight6, String ansnum6)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_CREATOR)
            {
                return RedirectToAction("Invalid", "Home");
            }
            bool errorspresent = false;
            int weightInt = 0;
            int ansnumInt = 0;

            CultureInfo culture = new CultureInfo("en-AU");
            culture.DateTimeFormat.ShortDatePattern = "d/M/yyyy";
            culture.DateTimeFormat.ShortTimePattern = string.Empty;
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

            answerModel a = new answerModel();
            questionModel q = new questionModel();
            q = q.getQuestion(questionid);

            int type = q.questiontype;

            List<answerModel> list = a.displayAnswers(questionid);

            if (list.Count >= 6 && (q.questiontype == 3 || q.questiontype == 4 || q.questiontype == 5 || q.questiontype == 6))
            {
                ViewData["mastererror"] = "This Multiple Choice Question is at the limit of 10 answers. Please remove a previous answer before creating another.";
                ViewData["questionid"] = questionid;
                return View();
            }

            /*Weight*/
            if (!int.TryParse(weight, out weightInt) || weight == null)
            {
                ViewData["weighterror"] = "Above field must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(weight1, out weightInt) || weight1 == null)
            {
                ViewData["weighterror1"] = "Above field must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(weight2, out weightInt) || weight2 == null)
            {
                ViewData["weighterror2"] = "Above field must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(weight3, out weightInt) || weight3 == null)
            {
                ViewData["weighterror3"] = "Above field must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(weight4, out weightInt) || weight4 == null)
            {
                ViewData["weighterror4"] = "Above field must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(weight5, out weightInt) || weight5 == null)
            {
                ViewData["weighterror5"] = "Above field must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(weight6, out weightInt) || weight6 == null)
            {
                ViewData["weighterror6"] = "Above field must contain a number!";
                errorspresent = true;
            }

            /*Answer*/
            if (answer == "")
            {
                ViewData["answererror"] = "Above field must contain an answer!";
                errorspresent = true;
            }
            if (answer1 == "")
            {
                ViewData["answererror1"] = "Above field must contain an answer!";
                errorspresent = true;
            }
            if (answer2 == "")
            {
                ViewData["answererror2"] = "Above field must contain an answer!";
                errorspresent = true;
            }
            if (answer3 == "")
            {
                ViewData["answererror3"] = "Above field must contain an answer!";
                errorspresent = true;
            }
            if (answer4 == "")
            {
                ViewData["answererror4"] = "Above field must contain an answer!";
                errorspresent = true;
            }
            if (answer5 == "")
            {
                ViewData["answererror5"] = "Above field must contain an answer!";
                errorspresent = true;
            }
            if (answer6 == "")
            {
                ViewData["answererror6"] = "Above field must contain an answer!";
                errorspresent = true;
            }

            /*Ans Num*/
            if (!int.TryParse(ansnum, out ansnumInt) || ansnum == null)
            {
                ViewData["ansnumerror"] = "Answer Number must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(ansnum1, out ansnumInt) || ansnum1 == null)
            {
                ViewData["ansnumerror1"] = "Answer Number must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(ansnum2, out ansnumInt) || ansnum2 == null)
            {
                ViewData["ansnumerror2"] = "Answer Number must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(ansnum3, out ansnumInt) || ansnum3 == null)
            {
                ViewData["ansnumerror3"] = "Answer Number must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(ansnum4, out ansnumInt) || ansnum4 == null)
            {
                ViewData["ansnumerror4"] = "Answer Number must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(ansnum5, out ansnumInt) || ansnum5 == null)
            {
                ViewData["ansnumerror5"] = "Answer Number must contain a number!";
                errorspresent = true;
            }
            if (!int.TryParse(ansnum6, out ansnumInt) || ansnum6 == null)
            {
                ViewData["ansnumerror6"] = "Answer Number must contain a number!";
                errorspresent = true;
            }

            if (errorspresent == false)
            {

                try
                {
                    new answerModel().createAnswer(answer, correct, int.Parse(weight), int.Parse(ansnum), questionid);
                    new answerModel().createAnswer(answer1, correct1, int.Parse(weight1), int.Parse(ansnum1), questionid);
                    new answerModel().createAnswer(answer2, correct2, int.Parse(weight2), int.Parse(ansnum2), questionid);
                    new answerModel().createAnswer(answer3, correct3, int.Parse(weight3), int.Parse(ansnum3), questionid);
                    new answerModel().createAnswer(answer4, correct4, int.Parse(weight4), int.Parse(ansnum4), questionid);
                    new answerModel().createAnswer(answer5, correct5, int.Parse(weight5), int.Parse(ansnum5), questionid);
                    new answerModel().createAnswer(answer6, correct6, int.Parse(weight6), int.Parse(ansnum6), questionid);

                    ViewData["created"] = "Created Answer: " + answer;

                    ViewData["questionid"] = questionid;
                    return View();
                }
                catch (Exception e)
                {
                    ViewData["error1"] = "!ERROR: " + e.Message + " inner: " + e.InnerException;
                    ViewData["questionid"] = questionid;
                    return View();
                }
            }
            else
            {
                // We have errors. sent to user posthaste!
                ViewData["mastererror"] = "There are errors marked in the form. Please correct these and resubmit";
                ViewData["questionid"] = questionid;
                return View();
            }
        }
예제 #4
0
        public ActionResult Edit(int answerid, String answer, int correct, String weight, int questionid, String ansnum)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_CREATOR)
            {
                return RedirectToAction("Invalid", "Home");
            }
            int weightInt = 0;
            int ansnumInt = 0;
            if (!int.TryParse(weight, out weightInt) || weight == null)
            {
                ViewData["weighterror"] = "Above field must contain a number!";
                //errorspresent = true;
            }

            if (answer == "")
            {
                ViewData["answererror"] = "Above field must contain an answer!";
            }

            if (!int.TryParse(ansnum, out ansnumInt))
            {
                ViewData["ansnumerror"] = "Answer Number must contain a number!";
            }

            CultureInfo culture = new CultureInfo("en-AU");
            culture.DateTimeFormat.ShortDatePattern = "d/M/yyyy";
            culture.DateTimeFormat.ShortTimePattern = string.Empty;
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

            try
            {
               answerModel a = new answerModel();
               a = a.getAnswer(answerid);

               /* Create a record of the old answer in the Answer History table */
               new answerHistoryModel(answerid).createAnswerHistory(a.answerid, a.answer, a.correct, a.weight, a.ansnum);

               /* Update the answer*/
               a.updateAnswer(answerid, answer, correct, int.Parse(weight), int.Parse(ansnum));

               ViewData["questionid"] = questionid;

               ViewData["edited"] = "Updated Answer: " + answer;
               return View(a);
            }
            catch(Exception e)
            {
                ViewData["weighterror"] = "OMG THERE IS AN ERROR "+ e.Message;
                answerModel a = new answerModel().getAnswer(answerid);
                ViewData["questionid"] = questionid;
                return View(a);
            }
        }
예제 #5
0
        public ActionResult Delete(int answerid, int questionid, String name)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_MASTER)
            {
                return RedirectToAction("Invalid", "Home");
            }

            answerModel a = new answerModel(answerid);
            a.deleteAnswer();
            return RedirectToAction("Index", "Answer", new {id = questionid, name = name  });
        }
예제 #6
0
        public ActionResult Test(int questionid, String name, int num_response)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_MASTER)
            {
                return RedirectToAction("Invalid", "Home");
            }

            CultureInfo culture = new CultureInfo("en-AU");
            culture.DateTimeFormat.ShortDatePattern = "d/M/yyyy";
            culture.DateTimeFormat.ShortTimePattern = string.Empty;
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

            answerModel a = new answerModel();

            List<answerModel> list = a.displayAnswers(questionid);

            if (list.Count < 1) {
                   ViewData["message"] = "This question does not have any answers, create a question and try again.";
                return View(list);
            }

            ViewData["name"] = name;
            ViewData["qid"] = questionid;
            ViewData["num"] = num_response;
            return View(list);
        }
예제 #7
0
        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 });
        }
예제 #8
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);
        }
예제 #9
0
        public ActionResult ConfirmationPage(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");
            }

            PollAnswerAndSession pollAndQuestion = new PollAnswerAndSession();

            List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid);

            pollAndQuestion.sessionData = new pollModel().displaySessionDetails(sessionid);
            pollAndQuestion.questionData = tempList;
            List<List<answerModel>> sorted = new List<List<answerModel>>();
            List<int> questionCheck = new List<int>();

            List<List<int>> orderedResponses = new List<List<int>>();

            foreach (var item in pollAndQuestion.questionData)
            {
                List<answerModel> test = new answerModel().displayAnswers(item.questionid);
                sorted.Add(test);
                List<int> unorderedResponses = new List<int>();
                foreach (var answer in test)
                {
                    unorderedResponses.Add(new responseModel().countResponse(answer.answerid));
                }
                orderedResponses.Add(unorderedResponses);
            }

            pollAndQuestion.answerData = sorted;
            pollAndQuestion.responseData = orderedResponses;

            return View(pollAndQuestion);
        }
예제 #10
0
        // Function to generate a dropdown list dynamically, and automatically select a value if a user has answered
        // this question and the answer is stored in the database
        private void buildSelectList(List<answerModel> answerList, List<int?> selectedAnswer)
        {
            List<SelectListItem> ListItems = new List<SelectListItem>();

            ListItems.Add(new SelectListItem
            {
                Text = "",
                Value = null,
                Selected = true,
            });

            foreach (var answer in answerList)
            {
                ListItems.Add(new SelectListItem
                {
                    Text = answer.answer,
                    Value = answer.answerid.ToString(),
                });

            }

            int i = 1;
            ViewData["RankingAnswerHistory"] += "Your previous answers: ";
            ViewData["RankingAnswerHistory"] += "<br />";
            foreach (int a in selectedAnswer)
            {
                ViewData["RankingAnswerHistory"] += "Preference " + i + ": ";
                ViewData["RankingAnswerHistory"] += new answerModel().getFeedback(a);
                ViewData["RankingAnswerHistory"] += "<br />";
                i++;
            }

            ViewData["RankingAnswerHistory"] += "<br />";
            ViewData["RankingAnswerHistory"] += "Please select your answers again";
            ViewData["RankingAnswerHistory"] += "<br />";

            ViewData["RankingAnswerList"] = ListItems;
        }