public ActionResult DeleteGroupTest(int?id) { GroupTestService.EnableTracking(); var groupTest = GroupTestService.GetByPK(id.Value); GroupTestService.DeleteAndSubmit(groupTest); return(OkJson()); }
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)))); }