Пример #1
0
        public ActionResult Index()
        {
            List <DisplayStudentTestsModel> testList = new List <DisplayStudentTestsModel>();

            try
            {
                IToken            temp     = _tokenStore;
                List <ModelToken> curToken = _tokenStore.GetTokensByUsername(User.Identity.Name).ToList();
                curToken.ForEach(token =>
                {
                    DisplayStudentTestsModel cur = new DisplayStudentTestsModel(token.TestID);
                    ModelTest curTest            = _testStore.GetTest(token.TestID);
                    cur.TestName = curTest.TestName;
                    cur.Date     = curTest.StartTime;

                    String markStud = SumStudAnswerMarks(_studentAnswer.GetStudentAnswersByStudentByTest(User.Identity.Name, token.TestID)) ?? "n/a";
                    String markTest = "";
                    if (!markStud.Equals("n/a"))
                    {
                        markTest = SumTestMarks(_question.GetQuestionsByTest(token.TestID)) ?? "n/a";
                    }
                    cur.Mark = markStud + " / " + markTest;
                    testList.Add(cur);
                });
            }
            catch (NullReferenceException e)
            {
                return(View());
            }

            return(View(testList));
        }
Пример #2
0
        public ActionResult ViewTest(int TestID)
        {
            ModelTest curTest = _testStore.GetTest(TestID);
            //init
            //Check test completion
            String Username = User.Identity.Name;
            List <ModelStudentAnswer> curStud =
                _studentAnswerStore.GetStudentAnswersByStudentByTest(Username, TestID).ToList();
            List <ModelQuestion> questions = _questionStore.GetQuestionsByTest(TestID).ToList();
            List <StudentTestQuestionAnswerModel> testQuestions = new List <StudentTestQuestionAnswerModel>();

            int iCount = 1;

            questions.ForEach(cur => {
                StudentTestQuestionAnswerModel item = new StudentTestQuestionAnswerModel(cur.QuestionID);
                item.QuestionText = cur.Instruction;
                //init
                item.QuestionFlagged = false;
                item.QuestionNum     = iCount;
                item.Username        = User.Identity.Name;
                item.QuestionMark    = cur.MaxMark;
                testQuestions.Add(item);
                iCount++;
            });
            StudentTestQuestionAnswerModel.instance = testQuestions;

            //may the user write the test?

            Boolean found = false;

            foreach (ModelStudentAnswer cur in curStud)
            {
                //can maybe add to Token[ bool: TestSubmitted]
                if (cur.MarkObtained != 0 || !cur.Answer.Equals(""))
                {
                    return(RedirectToAction("ViewTestResults"));
                }
            }

            DateTime now       = DateTime.Now;
            DateTime startTime = curTest.StartTime;
            DateTime endTime   = curTest.EndTime;

            if (startTime > now)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            else if (now > endTime)
            {
                curStud.ForEach(cur => {
                    foreach (StudentTestQuestionAnswerModel curAns in testQuestions)
                    {
                        if (cur.QuestionID == curAns.QuestionID)
                        {
                            int pos = testQuestions.IndexOf(curAns);
                            testQuestions[pos].MarkObtained    = cur.MarkObtained;
                            testQuestions[pos].QuestionAnswer  = cur.Answer;
                            testQuestions[pos].QuestionFlagged = cur.Flagged;
                            break;
                        }
                    }
                });
                return(RedirectToAction("ViewTestResults"));
            }

            //return RedirectToAction("getDB");
            return(View(testQuestions.First()));
        }