Exemplo n.º 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))));
        }
Exemplo n.º 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))));
        }
Exemplo n.º 3
0
        public IQueryable <GroupTest> GetGroupTests(decimal studentId)
        {
            var groupIds = this.GetAll(x => x.Group.Course_TC == CourseTC.Test &&
                                       x.Student_ID == studentId).Select(x => x.Group_ID).ToList();

            if (!groupIds.Any())
            {
                return(Enumerable.Empty <GroupTest>().AsQueryable());
            }
            GroupTestService.LoadWith(x => x.Test);
            GroupTestService.LoadWith(x => x.TestPassRule);
            var today      = DateTime.Today;
            var groupTests = GroupTestService.GetAll(x => groupIds.Contains(x.GroupInfo.Group_ID) &&
                                                     x.DateBegin <= today && x.DateEnd >= today);

            return(groupTests);
        }