示例#1
0
        public ActionResult OpenResult(int id)
        {
            var testResult = resultFacade.GetResultWithId(id);
            var resList    = testResult.ResultString.Split(';');

            resList = resList.Take(resList.Length - 1).ToArray();
            var arrRes = resList.Select(s => s.Split(','))
                         .Select(strings => new CheckboxModel {
                Id = int.Parse(strings[0]), Selected = Convert.ToBoolean(strings[1])
            })
                         .ToArray();



            var testTmp = testFacade.GetTestTemplateById(testResult.TestTemplateId);
            var que     = new QuestionFacade().GetListOfQuestionsByTheirAnswers(arrRes.Select(s => s.Id).ToList());
            var blres   = new List <bool>();
            var answers = que.SelectMany(s => s.Answers).ToList();

            for (int i = 0; i < answers.Count(); i++)
            {
                blres.Add(answers[i].Correct == arrRes[i].Selected);
            }



            var model = new ResultModel
            {
                Id             = testTmp.Id,
                Name           = testTmp.Name,
                CompletionTime = testTmp.CompletionTime,
                Date           = testTmp.Date,
                NumOfQuestions = testTmp.NumOfQuestions,
                Questions      = que,
                Answers        = arrRes,
                ResultBools    = blres,
                Score          = testResult.ResultPoints
            };

            return(View(model));
        }
示例#2
0
        public ActionResult TakeTest(int id)
        {
            var testTmp = testFacade.GetTestTemplateById(id);

            var time2 = testTmp.Date + testTmp.CompletionTime;


            if (DateTime.Now > time2 || DateTime.Now < testTmp.Date)
            {
                TempData["error"] = "Cannot start the test!";
                return(RedirectToAction("Index"));
            }



            var que = new QuestionFacade().GetNumOfRandQuestionsFromThematicAreas(testTmp.NumOfQuestions, testTmp.ThematicAreas);

            var answs = que.SelectMany(s => s.Answers)
                        .Select(tmp => new CheckboxModel {
                Id = tmp.Id, Selected = false
            })
                        .ToArray();


            var model = new TestActiveModel
            {
                Id             = testTmp.Id,
                Name           = testTmp.Name,
                CompletionTime = testTmp.CompletionTime,
                Date           = testTmp.Date,
                NumOfQuestions = testTmp.NumOfQuestions,
                Questions      = que,
                Answers        = answs
            };

            return(View(model));
        }