public ActionResult Edit(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.ExamSchedule.Edit(); vm.ExamList = Exam.Controllers.ExamController.SelectList(); if (id != 0) { var tb = (from p in db.Table <Exam.Entity.tbExamSchedule>() where p.Id == id select new Dto.ExamSchedule.Edit { Id = p.Id, ExamScheduleName = p.ExamScheduleName, ExamId = p.tbExam.Id, ScheduleNo = p.ScheduleNo, ScheduleDate = p.ScheduleDate, FromDate = p.FromDate, ToDate = p.ToDate }).FirstOrDefault(); if (tb != null) { vm.ExamScheduleEdit = tb; } } return(View(vm)); } }
public ActionResult Edit(Models.ExamSchedule.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.ExamScheduleEdit.Id == 0) { var tb = new Exam.Entity.tbExamSchedule(); tb.tbExam = db.Set <Exam.Entity.tbExam>().Find(vm.ExamScheduleEdit.ExamId); tb.ExamScheduleName = vm.ExamScheduleEdit.ExamScheduleName; tb.ScheduleNo = Convert.ToInt32(vm.ExamScheduleEdit.ScheduleNo); tb.ScheduleDate = vm.ExamScheduleEdit.ScheduleDate; tb.FromDate = vm.ExamScheduleEdit.FromDate; tb.ToDate = vm.ExamScheduleEdit.ToDate; db.Set <Exam.Entity.tbExamSchedule>().Add(tb); if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加场次设置"); } } else { var tb = (from p in db.Table <Exam.Entity.tbExamSchedule>() where p.Id == vm.ExamScheduleEdit.Id select p).FirstOrDefault(); if (tb != null) { tb.tbExam = db.Set <Exam.Entity.tbExam>().Find(vm.ExamScheduleEdit.ExamId); tb.ExamScheduleName = vm.ExamScheduleEdit.ExamScheduleName; tb.ScheduleNo = Convert.ToInt32(vm.ExamScheduleEdit.ScheduleNo); tb.ScheduleDate = vm.ExamScheduleEdit.ScheduleDate; tb.FromDate = vm.ExamScheduleEdit.FromDate; tb.ToDate = vm.ExamScheduleEdit.ToDate; if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改场次设置"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } } return(Code.MvcHelper.Post(error)); } }