Beispiel #1
0
        //add not existed question
        public ActionResult AddExistedQuestionToTest(int questionId, int testId)
        {
            QuestionService questionService = new QuestionService();
            TestService     testService     = new TestService();

            if (testService.AddQuestionToTest(questionId, testId))
            {
                return(RedirectToAction("ShowTestQuestions", "Manager", new { testId = testId }));
            }
            else
            {
                return(RedirectToAction("ShowTestQuestions", "Manager", new { testId = testId }));
            }
        }
Beispiel #2
0
        //post meethod
        public ActionResult CreateQAToTestDB(string CATEGORY, int POINT, string QUESTION_TEXT, string testId, string ANSWER1, string ANSWER2, string ANSWER3, string ANSWER4)
        {
            QUESTION        question        = new QUESTION();
            QuestionService questionService = new QuestionService();

            question.CATEGORY  = CATEGORY;
            question.POINT     = POINT;
            question.QUESTION1 = QUESTION_TEXT;
            if (questionService.create(question))
            {
                ANSWER        answer        = new ANSWER();
                AnswerService answerService = new AnswerService();
                string[]      ans           = new string[4] {
                    ANSWER1, ANSWER2, ANSWER3, ANSWER4
                };
                for (int i = 0; i < 4; i++)
                {
                    answer.QUESTION_ID = questionService.GetLastQuestionId();
                    answer.ANSWER1     = ans[i];
                    if (i == 0)
                    {
                        answer.STATUS = true;
                    }
                    else
                    {
                        answer.STATUS = false;
                    }
                    if (answerService.create(answer) == false)
                    {
                        return(RedirectToAction("CreateQAToTest", "Manager", new { error = "Something wrong with the Answers please create it again", testId = testId }));
                    }
                }
                TestService testService = new TestService();
                if (testService.AddQuestionToTest(questionService.GetLastQuestionId(), Int32.Parse(testId)))
                {
                    return(RedirectToAction("ShowTestQuestions", "Manager", new { testId = testId }));
                }
                return(RedirectToAction("CreateQAToTest", "Manager", new { error = "Create Q&A successfully", testId = testId }));
            }
            else
            {
                return(RedirectToAction("CreateQAToTest", "Manager", new { error = "Something wrong with the Question", testId = testId }));
            }
        }