Exemplo n.º 1
0
        public IActionResult AddTest([FromBody] TestStorage test)
        {
            test.PublishDate = DateTime.Now.ToString("yyyy-MM-dd");
            string type    = HttpContext.Request.Query["type"];
            string direct  = HttpContext.Request.Query["direct"];
            string account = HttpContext.Session.GetString("admin");

            test.Publisher = admin.GetByAccount(account).name;
            if (direct != "")
            {
                test.Grade = "exam";
            }
            switch (type)
            {
            case "choice":
                test.Type = TestSort.choice.ToString();
                break;

            case "blank":
                test.Type = TestSort.blank.ToString();
                break;

            case "judege":
                test.Type = TestSort.judege.ToString();
                break;

            case "answer":
                test.Type = TestSort.answer.ToString();
                break;

            default:
                break;
            }
            var a = Test.AddTest(test);

            if (a != null)
            {
                if (direct != "")
                {
                    Exam.AddTestToExam(new List <ExamContent>()
                    {
                        new ExamContent {
                            ExamId = Convert.ToInt32(direct), TestId = a.Id
                        }
                    });
                }
                return(Content("1"));
            }
            else
            {
                return(Content("0"));
            }
        }
Exemplo n.º 2
0
        public IActionResult AddTestsToExam()
        {
            var exam    = Exam.FindExamById(Convert.ToInt32(HttpContext.Request.Query["exam"]));
            var TestIds = HttpContext.Request.Form["id"].ToString().Split(',');
            List <ExamContent> contents = new List <ExamContent>();

            for (int i = 0; i < TestIds.Length; i++)
            {
                if (Exam.JudgeIsExist(exam.Id, Convert.ToInt32(TestIds[i])))
                {
                    continue;
                }
                contents.Add(new ExamContent {
                    ExamId = exam.Id, TestId = Convert.ToInt32(TestIds[i])
                });
            }
            Exam.AddTestToExam(contents);
            return(Content("1"));
        }