Exemple #1
0
        public ActionResult Index(TestResult testResult)
        {
            Test activeTest = testRepository.Tests.FirstOrDefault(t => t.TestID == testResult.TestID);

            if (testResult.UserName == null || activeTest == null)
            {
                return(RedirectToAction("LogIn", "Account"));
            }

            if (testResult.Answers.Count >= activeTest.Questions.Count ||
                testResult.BeginTime.AddSeconds(activeTest.TimeSec) < DateTime.Now)
            {
                testResult.IsDone     = true;
                testResult.FinishTime = DateTime.Now;
                testResult.CheckAnswers(activeTest);
                resultRepository.AddTestResult(testResult);
                return(RedirectToAction("Result"));
            }

            ViewData["UserName"]    = testResult.UserName;
            ViewData["numQuestion"] = testResult.Answers.Count;
            ViewData["Question"]    = activeTest.Questions[testResult.Answers.Count];
            ViewData["QuestionID"]  = activeTest.Questions[testResult.Answers.Count].QuestionID;
            ViewData["TimeLeft"]    = Math.Round(activeTest.TimeSec - (DateTime.Now - testResult.BeginTime).TotalSeconds);

            return(View(activeTest));
        }
Exemple #2
0
        public ActionResult LogIn(string UserName, TestResult testResult)
        {
            if (testResult.TestID != "")
            {
                resultRepository.AddTestResult(testResult);
            }

            TestResult res = resultRepository.LastTestThisName(UserName);

            Test temp;

            if (res == null || res.IsDone)
            {
                try
                {
                    temp = res == null ? testRepository.Tests[0] : testRepository.Tests[testRepository.Tests.FindIndex(t => t.TestID == res.TestID) + 1];
                }
                catch (IndexOutOfRangeException)
                {
                    return(RedirectToAction("AllResults", "Results"));
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException(e.Message);
                }

                testResult.Reset(UserName, temp.TestID);
            }
            else
            {
                testResult = (TestResult)res.Clone();
            }



            FormsAuthentication.SetAuthCookie(UserName, false);

            return(RedirectToAction("Index", "Test"));
        }