public ActionResult Edit(Models.StudyApply.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.StudyApplyEdit.Id == 0) { var tb = new Study.Entity.tbStudyApply(); tb.Remark = vm.StudyApplyEdit.Remark; tb.tbStudy = db.Set <Study.Entity.tbStudy>().Find(vm.StudyId); tb.tbStudent = db.Table <Student.Entity.tbStudent>().Where(d => d.tbSysUser.Id == Code.Common.UserId).FirstOrDefault(); tb.CheckStatus = XkSystem.Code.EnumHelper.CheckStatus.None; tb.InputDate = DateTime.Now; db.Set <Study.Entity.tbStudyApply>().Add(tb); if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加晚自习申请"); } } else { var tb = (from p in db.Table <Study.Entity.tbStudyApply>() where p.Id == vm.StudyApplyEdit.Id select p).FirstOrDefault(); if (tb != null) { tb.Remark = vm.StudyApplyEdit.Remark; if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改晚自习申请"); } } else { error.AddError(Resources.LocalizedText.MsgNotFound); } } } return(Code.MvcHelper.Post(error, Url.Action("List"))); } }
public ActionResult Edit(int id = 0, int studyId = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.StudyApply.Edit(); if (id != 0) { var tb = (from p in db.Table <Study.Entity.tbStudyApply>() where p.Id == id select new Dto.StudyApply.Edit { Id = p.Id, No = p.No, Remark = p.Remark }).FirstOrDefault(); if (tb != null) { vm.StudyApplyEdit = tb; } } return(View(vm)); } }