Exemple #1
0
        public ActionResult EditGroupTest(int groupInfoId, int?id)
        {
            var groupTest = new GroupTest();

            groupTest.TestPassRule = new TestPassRule();
            var modules        = new List <TestModule>();
            var modulePercents = new Dictionary <int, int>();

            if (id.HasValue)
            {
                GroupTestService.LoadWith(x => x.Test, x => x.TestPassRule);
                groupTest      = GroupTestService.GetByPK(id.Value);
                modulePercents = EntityUtils.GetModulePercents(groupTest.TestPassRule);
                modules        = TestModuleService.GetForTest(groupTest.TestId).ToList();
            }
            else
            {
                var groupId = GetGroupIdForInfo(groupInfoId);
                var group   = GroupService.GetByPK(groupId);
                groupTest.GroupInfoId = groupInfoId;
                groupTest.DateBegin   = group.DateBeg ?? DateTime.Now;
                groupTest.DateEnd     = group.DateEnd ?? DateTime.Now;
            }
            var model = new GroupTestEditVM {
                GroupTest      = groupTest,
                Modules        = modules,
                ModulePercents = modulePercents,
            };

            return(BaseView(new PagePart(new GroupTestEditView().Init(model, Url))));
        }
Exemple #2
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))));
        }
Exemple #3
0
 private string GetTitle(GroupTestEditVM model)
 {
     return(GetCrudTitle(model.GroupTest.Id, "теста группы"));
 }