public ActionResult Edit(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.PerformGroup.Edit(); if (id != 0) { var tb = (from p in db.Table <Perform.Entity.tbPerformGroup>() where p.Id == id select p).FirstOrDefault(); if (tb != null) { vm.PerformGroupEdit = tb; } } return(View(vm)); } }
public ActionResult Edit(Models.PerformGroup.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); var fail = Json(new { Status = decimal.Zero, Message = "操作失败!" }); if (error.Count != decimal.Zero) { return(fail); } var tb = new Perform.Entity.tbPerformGroup(); #region 【新增或修改数据】 //新增 if (vm.PerformGroupEdit.Id == 0) { tb.No = vm.PerformGroupEdit.No == null?db.Table <Perform.Entity.tbPerformGroup>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PerformGroupEdit.No; tb.PerformGroupName = vm.PerformGroupEdit.PerformGroupName; tb.tbPerform = db.Set <Perform.Entity.tbPerform>().Find(vm.PerformId); tb.MaxScore = vm.PerformGroupEdit.MaxScore; tb.MinScore = vm.PerformGroupEdit.MinScore; db.Set <Perform.Entity.tbPerformGroup>().Add(tb); XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加评价项分组"); } else//修改 { tb = (from p in db.Table <Perform.Entity.tbPerformGroup>() where p.Id == vm.PerformGroupEdit.Id select p).FirstOrDefault(); if (tb == null) { error.AddError(Resources.LocalizedText.MsgNotFound); return(fail); } XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改评价项分组"); tb.No = vm.PerformGroupEdit.No == null?db.Table <Perform.Entity.tbPerformGroup>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PerformGroupEdit.No; tb.PerformGroupName = vm.PerformGroupEdit.PerformGroupName; tb.MinScore = vm.PerformGroupEdit.MinScore; tb.MaxScore = vm.PerformGroupEdit.MaxScore; } #endregion #region 【事务提交】 using (TransactionScope scope = new TransactionScope()) { var result = new PerformCourseController().SaveCourseNode(db, Request["txtSubjectIds"], tb, vm.PerformId); if (result.Status == decimal.Zero) { return(Json(result)); } db.SaveChanges(); scope.Complete(); return(Code.MvcHelper.Post(null, Url.Action("List", new { performId = vm.PerformId }))); } #endregion } }