コード例 #1
0
ファイル: TestEditController.cs プロジェクト: dKluev/Site
        public ActionResult EditModuleSet(ModuleSetVM model)
        {
            var moduleSet = model.ModuleSet;

            EditTestPermission(moduleSet.TestId);
            EntityUtils.SetModulePercents(moduleSet.TestPassRule, model.ModulePercents);
            var validators = new TestValidators(ModelState);

            validators.Validate(moduleSet.TestPassRule);
            validators.Validate(moduleSet);
            if (!ModelState.IsValid)
            {
                return(ErrorJson());
            }
            TestModuleSetService.EnableTracking();
            TestModuleSetService.LoadWith(x => x.TestPassRule);
            if (moduleSet.Id == 0)
            {
                TestModuleSetService.InsertAndSubmit(moduleSet);
                return(UrlJson(Url.TestEdit().Urls.EditModuleSet(moduleSet.TestId, moduleSet.Id)));
            }
            var oldModel = TestModuleSetService.GetByPK(moduleSet.Id);

            oldModel.Update(moduleSet, x => x.Description, x => x.Number);
            oldModel.TestPassRule.UpdateBy(moduleSet.TestPassRule);
            EntityUtils.SetModulePercents(oldModel.TestPassRule, model.ModulePercents);
            TestModuleSetService.SubmitChanges();
            return(OkJson());
        }
コード例 #2
0
ファイル: TestRunController.cs プロジェクト: dKluev/Site
        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));
        }
コード例 #3
0
ファイル: TestEditController.cs プロジェクト: dKluev/Site
        public ActionResult GetModuleSets(int testId, AjaxGridRequest model)
        {
            var list = TestModuleSetService
                       .GetAll(x => x.TestId == testId).OrderBy(x => x.Number).Select(x =>
                                                                                      new { x.Id, x.Number, x.Description }).ToPagedList(model.Page - 1, model.Rows);

            return(JsonGet(new GridData(list.PageCount,
                                        model.Page,
                                        list.Count,
                                        list)));
        }
コード例 #4
0
        public ActionResult CoursePlanned(string courseTC)
        {
            var course = CourseService.GetByPK(courseTC);
            var testId = course.TestId;

            var moduleSets = TestModuleSetService.GetAll(x => x.TestId == testId)
                             .OrderBy(x => x.Number).ToList();
            var moduleStatuses = UserTestService.GetAll(x =>
                                                        x.IsBest && x.TestId == testId && x.TestModuleSetId.HasValue).ToList()
                                 .GroupBy(x => x.TestModuleSetId.Value)
                                 .ToDictionary(x => x.Key, x => x.First());

            var model = new CoursePlannedTestVM {
                ModuleSets = moduleSets,
                Statuses   = moduleStatuses,
                Course     = course,
            };


            return(BaseViewWithModel(new CoursePlannedTestView(), model));
        }
コード例 #5
0
        public ActionResult PlanTestUserStats(decimal groupId)
        {
            var testId     = GetTestForGroup(groupId);
            var studentIds = GetStudentIds(groupId);
            var users      = UserRepository.GetAll(u => studentIds.Contains(u.Student_ID.Value)).ToList();
            var userNames  = users.ToDictionary(x => x.UserID, x => x.FullName);
            var userIds    = users.Select(x => x.UserID).ToList();
            var userTests  = GetUserTests(testId.Value, userIds).ToList().GroupBy(x => x.TestModuleSetId.Value).ToList();
            var setIds     = userTests.Select(x => x.Key);
            var sets       = TestModuleSetService.GetByPK(setIds.Cast <object>())
                             .ToDictionary(x => x.Id, x => x);
            var setStats = userTests.Select(x =>
                                            new PlanTestUserStatsVM.ModuleSetStat(sets.GetValueOrDefault(x.Key),
                                                                                  x.ToList())).ToList();
            var model = new PlanTestUserStatsVM {
                GroupId        = groupId,
                ModuleSetStats = setStats,
                UserNames      = userNames
            };

            return(BaseViewWithModel(new PlanTestUserStatsView(), model));
        }
コード例 #6
0
ファイル: TestEditController.cs プロジェクト: dKluev/Site
        public ActionResult EditModuleSet(int testId, int?id)
        {
            EditTestPermission(testId);
            var model          = new ModuleSetVM();
            var set            = new TestModuleSet();
            var modulePercents = new Dictionary <int, int>();

            set.TestPassRule = new TestPassRule();
            if (id.HasValue)
            {
                TestModuleSetService.LoadWith(x => x.TestPassRule);
                set            = TestModuleSetService.GetByPK(id.Value);
                modulePercents = EntityUtils.GetModulePercents(set.TestPassRule);
            }
            else
            {
                set.TestId = testId;
                set.Number = (short)(1 + MaxModuleSetNumber(testId));
            }
            model.ModulePercents = modulePercents;
            model.ModuleSet      = set;
            model.Modules        = TestModuleService.GetForTest(testId).ToList();
            return(BaseViewWithModel(new ModuleSetEditView(), model));
        }
コード例 #7
0
ファイル: TestEditController.cs プロジェクト: dKluev/Site
 short MaxModuleSetNumber(int testId)
 {
     return(TestModuleSetService.GetAll(x => x.TestId == testId)
            .Max(x => (short?)x.Number).GetValueOrDefault());
 }