示例#1
0
        public ActionResult EditGroupTest(GroupTestEditVM model)
        {
            if (!LinqToSqlValidator.Validate(ModelState, model.GroupTest))
            {
                return(ErrorJson());
            }
            GroupTestService.EnableTracking();
            var newGroupTest = model.GroupTest;

            if (newGroupTest.Id == 0)
            {
                var rule = TestPassRuleService.FirstOrDefault(x => x.TestId == newGroupTest.TestId);
                if (newGroupTest.TestPassRule.QuestionCount == 0)
                {
                    newGroupTest.TestPassRule.UpdateBy(rule);
                }
                newGroupTest.TestPassRule.ModulePercents = rule.ModulePercents;
                Validate(newGroupTest);
                if (!ModelState.IsValid)
                {
                    return(ErrorJson());
                }
                GroupTestService.InsertAndSubmit(newGroupTest);
                return(UrlJson(Url.Action <GroupTestController>(c => c.EditGroupTest(newGroupTest.GroupInfoId,
                                                                                     newGroupTest.Id))));
            }
            GroupTestService.LoadWith(x => x.TestPassRule);
            var groupTest = GroupTestService.GetByPK(newGroupTest.Id);
            var isNewTest = groupTest.TestId != newGroupTest.TestId;

            if (isNewTest)
            {
                var rule = TestPassRuleService.FirstOrDefault(x => x.TestId == newGroupTest.TestId);
                model.ModulePercents = EntityUtils.GetModulePercents(rule);
            }
            groupTest.Update(newGroupTest, x => x.TestId,
                             x => x.DateBegin, x => x.DateEnd, x => x.AttemptCount);
            groupTest.TestPassRule.UpdateBy(newGroupTest.TestPassRule);
            EntityUtils.SetModulePercents(groupTest.TestPassRule, model.ModulePercents);
            Validate(groupTest);
            if (!ModelState.IsValid)
            {
                return(ErrorJson());
            }
            GroupTestService.SubmitChanges();
            if (isNewTest)
            {
                return(UrlJson(Url.GroupTest().Urls.EditGroupTest(groupTest.GroupInfoId, groupTest.Id)));
            }
            return(UrlJson(Url.Action <GroupTestController>(c => c.EditGroupTest(groupTest.GroupInfoId,
                                                                                 groupTest.Id))));
        }
示例#2
0
        public ActionResult EditAnswer(TestAnswer model)
        {
            EditQuestionPermission(model.QuestionId);
            if (!LinqToSqlValidator.Validate(ModelState, model))
            {
                return(ErrorJson());
            }
            TestAnswerService.EnableTracking();
            if (model.Id == 0)
            {
                TestAnswerService.InsertAndSubmit(model);
                return(UrlJson(Url.TestEdit().Urls.EditAnswer(model.QuestionId, model.Id)));
            }
            var oldModel = TestAnswerService.GetByPK(model.Id);

            oldModel.Update(model, x => x.Description, x => x.IsRight, x => x.ComparableId, x => x.Sort);
            TestAnswerService.SubmitChanges();
            return(OkJson());
        }
示例#3
0
        public ActionResult EditQuestion(TestQuestion model)
        {
            EditTestPermission(model.TestId);
            if (!LinqToSqlValidator.Validate(ModelState, model))
            {
                return(ErrorJson());
            }
            TestQuestionService.EnableTracking();
            if (model.Id == 0)
            {
                TestQuestionService.InsertAndSubmit(model);
                return(UrlJson(Url.TestEdit().Urls.EditQuestion(model.TestId, model.Id)));
            }
            var oldModel = TestQuestionService.GetByPK(model.Id);

            oldModel.Update(model, x => x.Description, x => x.ModuleId);
            TestQuestionService.SubmitChanges();
            return(Json("ok"));
        }
示例#4
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"));
        }
示例#5
0
 public ActionResult EditModule(TestModule model)
 {
     if (!LinqToSqlValidator.Validate(ModelState, model))
     {
         return(ErrorJson());
     }
     EditTestPermission(model.TestId);
     TestModuleService.EnableTracking();
     if (model.Id == 0)
     {
         TestModuleService.InsertAndSubmit(model);
         return(UrlJson(Url.TestEdit().Urls.EditModule(model.TestId, model.Id)));
     }
     else
     {
         var module = TestModuleService.GetByPK(model.Id);
         module.Update(model, x => x.Name);
         TestModuleService.SubmitChanges();
     }
     return(Json("ok"));
 }