Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        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());
            }
        }