Beispiel #1
0
        public ActionResult EditTest(int?id)
        {
            var        test            = new Test();
            AjaxGridVM modulesModel    = null;
            AjaxGridVM moduleSetsModel = null;
            AjaxGridVM questionsModel  = null;
            var        modules         = new List <TestModule>();
            var        modulePercents  = new Dictionary <int, int>();

            if (id.HasValue)
            {
                TestService.LoadWith(x => x.TestPassRule);
                test = TestService.GetByPK(id);
                EditTestPermission(test.Id);
                modulesModel = new AjaxGridVM {
                    GetListUrl = Url.Action <TestEditController>(c => c.GetModules(id.Value, null)),
                    EditUrl    = Url.Action <TestEditController>(c => c.EditModule(id.Value, null)),
                    DeleteUrl  = Url.Action <TestEditController>(c => c.DeleteModule(null)),
                    Caption    = "Модули"
                };
                AddColumns <TestModule>(modulesModel, x => x.Name);
                moduleSetsModel = new AjaxGridVM {
                    GetListUrl = Url.Action <TestEditController>(c => c.GetModuleSets(id.Value, null)),
                    EditUrl    = Url.Action <TestEditController>(c => c.EditModuleSet(id.Value, null)),
                    Caption    = "План тестирования"
                };
                AddColumns <TestModuleSet>(moduleSetsModel, x => x.Number);
                AddColumns <TestModuleSet>(moduleSetsModel, x => x.Description);
                questionsModel = new AjaxGridVM {
                    GetListUrl = Url.Action <TestEditController>(c => c.GetQuestions(id.Value, null)),
                    EditUrl    = Url.Action <TestEditController>(c => c.EditQuestion(id.Value, null)),
                    DeleteUrl  = Url.Action <TestEditController>(c => c.DeleteQuestion(null)),
                    Caption    = "Вопросы"
                };
                AddColumns <TestQuestion>(questionsModel, x => x.Description);
                modulePercents = EntityUtils.GetModulePercents(test.TestPassRule);
                modules        = TestModuleService.GetAll(x => x.TestId == id.Value).ToList();
            }
            test.TestPassRule = test.TestPassRule ?? new TestPassRule();

            var testEditVM = new TestEditVM {
                Test       = test,
                CourseName = CourseService.AllCourseLinks()
                             .GetValueOrDefault(test.CourseTCList).GetOrDefault(x => x.WebName),
                Modules        = modules,
                ModulePercents = modulePercents
            };

            return(BaseView(
                       new PagePart(new TestEditView().Init(testEditVM, Url)),
                       modulesModel == null ? null : new PagePart(PartialViewNames.AjaxList, modulesModel),
                       questionsModel == null ? null : new PagePart(PartialViewNames.AjaxList, questionsModel),
                       moduleSetsModel == null || test.CompanyId.HasValue ? null : new PagePart(PartialViewNames.AjaxList, moduleSetsModel)
                       ));
        }
Beispiel #2
0
        public ActionResult EditTest(TestEditVM model)
        {
            SetUpdateDateAndLastChanger(model.Test);

            if (!LinqToSqlValidator.Validate(ModelState, model.Test))
            {
                return(ErrorJson());
            }
            TestService.EnableTracking();
            if (model.Test.Id == 0)
            {
                model.Test.Status    = TestStatus.Edit;
                model.Test.Author_TC = User.Employee_TC ?? Employees.Specweb;
                model.Test.CompanyId = User.CompanyID;
                EntityUtils.SetModulePercents(model.Test.TestPassRule, model.ModulePercents);
                TestService.InsertAndSubmit(model.Test);
                TestModuleService.EnableTracking();
                TestModuleService.CreateModulesFromCourse(model.Test);
                return(UrlJson(Url.Action <TestEditController>(c => c.EditTest(model.Test.Id))));
            }
            TestService.LoadWith(x => x.TestPassRule);
            var test        = TestService.GetByPK(model.Test.Id);
            var isNewCourse = test.CourseTCList != model.Test.CourseTCList;

            EditTestPermission(test.Id);
            test.Update(model.Test,
                        x => x.Description,
                        x => x.Name,
                        x => x.CourseTCList
                        );
            var newTestPassRule = model.Test.TestPassRule;

            test.TestPassRule.UpdateBy(newTestPassRule);
            EntityUtils.SetModulePercents(test.TestPassRule, model.ModulePercents);
            TestService.SubmitChanges();
            if (isNewCourse)
            {
                TestModuleService.EnableTracking();
                TestModuleService.CreateModulesFromCourse(model.Test);
            }
            return(Json("ok"));
        }
Beispiel #3
0
 private string GetTitle(TestEditVM model)
 {
     return(GetCrudTitle(model.Test.Id, "теста", model.Test.Name));
 }