public ActionResult Edit(Models.AttendanceType.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.AttendanceTypeEdit.Id == 0) { var tb = new Attendance.Entity.tbAttendanceType(); tb.No = vm.AttendanceTypeEdit.No == null?db.Table <Attendance.Entity.tbAttendanceType>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.AttendanceTypeEdit.No; tb.AttendanceTypeName = vm.AttendanceTypeEdit.AttendanceTypeName; db.Set <Attendance.Entity.tbAttendanceType>().Add(tb); if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加学生考勤类型"); } } else { var tb = (from p in db.Table <Attendance.Entity.tbAttendanceType>() where p.Id == vm.AttendanceTypeEdit.Id select p).FirstOrDefault(); if (tb != null) { tb.No = vm.AttendanceTypeEdit.No == null?db.Table <Attendance.Entity.tbAttendanceType>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.AttendanceTypeEdit.No; tb.AttendanceTypeName = vm.AttendanceTypeEdit.AttendanceTypeName; if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改学生考勤类型"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } } return(Code.MvcHelper.Post(error)); } }
public ActionResult Edit(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.AttendanceType.Edit(); if (id != 0) { var tb = (from p in db.Table <Attendance.Entity.tbAttendanceType>() where p.Id == id select p).FirstOrDefault(); if (tb != null) { vm.AttendanceTypeEdit = tb; } } return(View(vm)); } }