Ejemplo n.º 1
0
        public ActionResult Start(int id, string courseTC, int?moduleSetId)
        {
            var test      = TestService.GetFullTest(id);
            var groupTest = StudentInGroupService.GetUserGroupTest(id);

            if (groupTest != null && groupTest.AttemptCount.HasValue)
            {
                var count = UserTestService.GetUserTests(groupTest)
                            .Count(x => x.UserId == GetUserId(false));
                if (count >= groupTest.AttemptCount.Value)
                {
                    return(BaseView(new PagePart("Вы использовали все попытки для сдачи теста")));
                }
            }
            var userTests = GetCurrentTests();
            var userTest  = userTests.FirstOrDefault(x => x.TestId == id &&
                                                     x.UserId == GetUserId(courseTC != null));

            if (userTest == null)
            {
                var rule = test.TestPassRule;
                if (groupTest != null)
                {
                    rule = groupTest.TestPassRule;
                }
                if (moduleSetId.HasValue)
                {
                    rule = TestModuleSetService.GetValues(moduleSetId.Value,
                                                          x => x.TestPassRule);
                }
                var showAnswers = false;
//				if (User.GetOrDefault(x => x.Student_ID) > 0) {
//					var paidCourses = StudentService.GetPaidCourseTCs(User.Student_ID.Value);
//					showAnswers = test.CourseTCSplitList.Intersect(paidCourses).Any();
//				}
                userTest = SaveUserTest(id, test, rule, courseTC, moduleSetId, showAnswers);
            }

            var model = new TestRunVM {
                Test = test, UserTest = userTest
            };

            if (userTest.IsPrerequisite)
            {
                var otherPretests = CoursePrerequisiteService.GetTestIds(
                    courseTC).Skip(1).ToList();
                if (otherPretests.Any())
                {
                    model.OtherPreTestQuestions = GetQuestions(otherPretests).ToList();
                }
            }

            if (test.TestIds.Any())
            {
                model.OtherPreTestQuestions = GetQuestions(test.TestIds).ToList();
            }

            return(BaseView(new TestRunView(), model));
        }
Ejemplo n.º 2
0
 private List <int> GetAllTestIds(UserTest userTest)
 {
     if (userTest.Test.TestIds.Any())
     {
         return(userTest.Test.TestIds);
     }
     if (userTest.IsPrerequisite)
     {
         return(CoursePrerequisiteService.GetTestIds(
                    userTest.Course_TC).ToList());
     }
     return(_.List(userTest.TestId));
 }
Ejemplo n.º 3
0
        ActionResult GetDetailsView(int id, string courseTC, int?moduleSetId)
        {
            var test = TestService.GetByPK(id);

            if (courseTC != null && CoursePrerequisiteService.GetTestIds(
                    courseTC).All(x => x != id))
            {
                return(NotFound());
            }

            if (!StudentInGroupService.CalcTestIsActive(test))
            {
                return(NotFound());
            }
            return(BaseView(Views.TestRun.Details, new TestRunDetailsVM {
                Test = test,
                CourseName = DictionaryUtils.GetValueNotDefaultKey(
                    CourseService.GetAllActiveCourseNames(), courseTC),
                ModuleSetId = moduleSetId,
                CourseTC = courseTC,
            }));
        }