public ActionResult CreateMultipleChoice(String num, int questiontype, String question, int chartstyle, int pollid) { 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"); } 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; int numInt = 0; bool errorspresent = false; if (question == "") { ViewData["questionerror"] = "Above field must contain a question!"; errorspresent = true; } if(errorspresent == false) { try { //converts user num into string numInt = int.Parse(num); } catch (Exception e) { //Not an int. do not insert and throw view error to user. ViewData["error1"] = "!ERROR: " + e.Message; return View(); } try { questionModel q = new questionModel(); q.createQuestion(questiontype, question, chartstyle, numInt, pollid); q.createDefaultObjects(pollid, q.getMaxID()); ViewData["id"] = pollid; ViewData["created"] = "Created Question: " + question; return View(); } catch (Exception e) { // Something went bad and we couldn't edit. ViewData["error1"] = "!ERROR: " + e.Message; return View(); } } else { // We have errors. sent to user posthaste! ViewData["mastererror"] = "There are errors marked in the form. Please correct these and resubmit"; return View(); } }
public ActionResult CreateShortAnswer(int shortanswertype, String num, String question, int chartstyle, int pollid) { 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"); } // Allows insertion of Australian formatted dates 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; int numInt = 0; // Contains pollid number for display. i.e "Creating question for poll 1" ViewData["id"] = pollid; bool errorspresent = false; //returns the max question ID in the questions table int maxqid = new questionModel().getMaxID(); // VALIDATE FORM DATA! if (!int.TryParse(num,out numInt) || num == null) { ViewData["numerror"] = "Above field must contain a number!"; errorspresent = true; } if (question == "") { ViewData["questionerror"] = "Above field must contain a question!"; errorspresent = true; } if(errorspresent == false) { try { //Build question (Autoid, short answer type = 1, question text from form, date, pollid from poll it is created it questionModel q = new questionModel(); q.createQuestion(shortanswertype, question, chartstyle, numInt, pollid); q.createDefaultObjects(pollid, q.getMaxID()); ViewData["created"] = "Created Question: " + question; return View(); } catch (Exception e) { ViewData["error1"] = "!ERROR: "+e.Message; ViewData["id"] = pollid; return View(); } }else{ // We have errors. sent to user posthaste! ViewData["mastererror"] = "There are errors marked in the form. Please correct these and resubmit"; return View(); } }