displayAnswers() public method

Retrieves ANSWERS relating to a specified Question
public displayAnswers ( int questId ) : List
questId int ID of the question
return List
Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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);
        }