public ActionResult EditCourse() { ViewBag.Result = new List <Term>(); QuizDAO quizDao = new QuizDAOImpl(); string user = Request.Cookies["user"] == null ? "" : Request.Cookies["user"].Value; try { if (!String.IsNullOrEmpty(Request["id"]) && quizDao.CanAccess(user, Convert.ToInt32(Request["id"]))) { ViewBag.Result = new TermDAOImpl().GetTermsByQuizID(int.Parse(Request["id"])); List <Term> lst = ViewBag.Result; Quiz quiz = new QuizDAOImpl().getQuizByQuizId(int.Parse(Request["id"])); ViewBag.quiz = quiz; return(View()); } else { throw new Exception(); } } catch { return(Redirect("/error/404")); } }
public ActionResult Add(params string[] args) { string username = Request.Cookies["user"].Value; string quizName = Request["title"]; string quizDes = Request["description"]; int access = int.Parse(Request["quiz-access"]); List <Term> lstTerm = new List <Term>(); List <string> lstKey = Request.Form.GetValues("key").ToList <string>(); List <string> lstValue = Request.Form.GetValues("value").ToList <string>(); for (int i = 0; i < lstKey.Count; i++) { lstTerm.Add(new Term(lstKey[i], lstValue[i])); } try { QuizDAO quizDAO = new QuizDAOImpl(); TermDAO termDAO = new TermDAOImpl(); int quizId = quizDAO.AddQuiz(username, quizName, quizDes, access); foreach (Term x in lstTerm) { int result = termDAO.AddTerm(quizId, x); } return(Redirect("~/quiz/course")); } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteQuiz() { QuizDAO quizDao = new QuizDAOImpl(); string user = Request.Cookies["user"] == null ? "" : Request.Cookies["user"].Value; try { if (!String.IsNullOrEmpty(Request["id"]) && quizDao.CanAccess(user, Convert.ToInt32(Request["id"]))) { ViewBag.user = Request.Cookies["user"]; if (quizDao.DeleteQuiz(int.Parse(Request["id"]))) { return(Redirect("/quiz/course")); } else { throw new Exception(); } } else { throw new Exception(); } } catch { return(Redirect("/error/404")); } }
public ActionResult EditCourse(params string[] args) { QuizDAO quizDAO = new QuizDAOImpl(); TermDAO termDAO = new TermDAOImpl(); string username = Request.Cookies["user"].Value; string quizName = Request["title"]; string quizDes = Request["description"]; int access = int.Parse(Request["quiz-access"]); quizDAO.UpdateQuiz(int.Parse(Request["id"]), quizName, quizDes, access); List <Term> lstTerm = new List <Term>(); List <string> lstKey = Request.Form.GetValues("key").ToList <string>(); List <string> lstValue = Request.Form.GetValues("value").ToList <string>(); for (int i = 0; i < lstKey.Count; i++) { lstTerm.Add(new Term(lstKey[i], lstValue[i])); } try { foreach (Term x in lstTerm) { int result = termDAO.AddTerm(int.Parse(Request["id"]), x); } return(Redirect("~/quiz/course")); } catch (Exception ex) { return(View()); } }
public List <Term> Get(string name, int id) { QuizDAO quizDAO = new QuizDAOImpl(); if (quizDAO.CanAccess(name, id)) { return(new TermDAOImpl().GetTermsByQuizID(id)); } else { return(new List <Term>()); } }