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)))); }
public ActionResult DeleteGroupTest(int?id) { GroupTestService.EnableTracking(); var groupTest = GroupTestService.GetByPK(id.Value); GroupTestService.DeleteAndSubmit(groupTest); return(OkJson()); }
public ActionResult GetGroupTests(int groupInfoId, AjaxGridRequest model) { var list = GroupTestService .GetAll(x => x.GroupInfoId == groupInfoId) .Select(x => new { x.Id, TestId = x.Test.Name }).ToPagedList(model.Page - 1, model.Rows); return(JsonGet(new GridData(list.PageCount, model.Page, list.ItemCount, list))); }
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)))); }
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); }