示例#1
0
        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
        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));
        }
示例#3
0
        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));
        }