updateAnswer() public method

public updateAnswer ( int answerid, String answer, int correct, int weight, int ansnum ) : void
answerid int
answer String
correct int
weight int
ansnum int
return void
Ejemplo n.º 1
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 } );
        }
Ejemplo n.º 2
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);
            }
        }