public ActionResult Edit(Models.TeacherLevel.Edit vm) { var error = new List <string>(); if (error.Count == decimal.Zero) { using (var db = new XkSystem.Models.DbContext()) { if (vm.DataEdit.Id > 0) { var tb = db.Set <Teacher.Entity.tbTeacherLevel>().Find(vm.DataEdit.Id); tb.TeacherLevelName = vm.DataEdit.TeacherLevelName; tb.No = vm.DataEdit.No == null?db.Table <Teacher.Entity.tbTeacherLevel>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.DataEdit.No; } else { var tb = new Teacher.Entity.tbTeacherLevel() { TeacherLevelName = vm.DataEdit.TeacherLevelName, No = vm.DataEdit.No == null?db.Table <Teacher.Entity.tbTeacherLevel>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.DataEdit.No }; db.Set <Teacher.Entity.tbTeacherLevel>().Add(tb); } if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增/修改了教师级别"); } } } return(Code.MvcHelper.Post(error)); }
public ActionResult Edit(int id = 0) { var vm = new Models.TeacherLevel.Edit(); if (id > 0) { using (var db = new XkSystem.Models.DbContext()) { vm.DataEdit = (from p in db.Table <Teacher.Entity.tbTeacherLevel>() where p.Id == id select p).FirstOrDefault(); } } return(View(vm)); }