public ActionResult Edit(StaffApplication staffApplication) { if (ModelState.IsValid) { /*查找预留字段(value)*/ var fieldValueList = (from sar in db.StaffApplicationReserves join rf in db.ReserveFields on sar.FieldId equals rf.Id where sar.Number == staffApplication.Id select new StaffApplicationViewModel { Id = sar.Id, Description = rf.Description, Value = sar.Value }).ToList(); /*给预留字段赋值*/ foreach (var temp in fieldValueList) { StaffApplicationReserve sar = db.StaffApplicationReserves.Find(temp.Id); sar.Value = Request[temp.Description]; db.SaveChanges(); } StaffApplication staffApplications = db.StaffApplications.Find(staffApplication.Id); staffApplications.ChangeTime = DateTime.Now; staffApplications.ChangePerson = base.Name; staffApplications.ApplyDate = staffApplication.ApplyDate; staffApplications.HopeLeaveDate = staffApplication.HopeLeaveDate; staffApplications.LeaveType = staffApplication.LeaveType; staffApplications.LeaveReason = staffApplication.LeaveReason; staffApplications.Remark = staffApplication.Remark; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(staffApplication)); }
public void AddReserves(StaffApplication staffApplication) { db.SaveChanges(); var fieldList = (from p in db.ReserveFields join q in db.TableNameContrasts on p.TableNameId equals q.Id where q.TableName == "StaffApplications" select p).ToList(); ViewBag.fieldList = fieldList; /*遍历,保存员工基本信息预留字段*/ foreach (var temp in fieldList) { StaffApplicationReserve sar = new StaffApplicationReserve(); sar.Number = staffApplication.Id; sar.FieldId = temp.Id; sar.Value = Request[temp.FieldName]; /*占位,为了在Index中显示整齐的格式*/ if (sar.Value == null) { sar.Value = " "; } db.StaffApplicationReserves.Add(sar); db.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { /*Step1:删除预留字段*/ var item = (from sar in db.StaffApplicationReserves where sar.Number == id select new StaffApplicationViewModel { Id = sar.Id }).ToList(); foreach (var temp in item) { StaffApplicationReserve sar = db.StaffApplicationReserves.Find(temp.Id); db.StaffApplicationReserves.Remove(sar); } db.SaveChanges(); /*Step2:删除固定字段*/ StaffApplication staffApplications = db.StaffApplications.Find(id); db.StaffApplications.Remove(staffApplications); db.SaveChanges(); return(RedirectToAction("Index")); }