Exemple #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());
        }
Exemple #2
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));
        }