//更新申请,含明细 public ActionResult Update(string json) { var rdto = new ResultMessages(); rdto.Message = ""; JavaScriptSerializer jss = new JavaScriptSerializer(); ReqVacationMain obj = jss.Deserialize<ReqVacationMain>(json); obj.ReqDate = DateTime.Now; try { ReqVacationMain oriObj = ctx.ReqVacationMains.Single(r => r.FormNo == obj.FormNo); oriObj.ReqDate = obj.ReqDate; oriObj.VacationType = obj.VacationType; oriObj.DaysCnt = obj.DaysCnt; oriObj.ReplacedDay = obj.ReplacedDay; oriObj.Cause = obj.Cause; oriObj.StatusId = obj.StatusId; foreach (var v in obj.ReqVacationSubs) { ReqVacationSub reqSub = null; if (v.Id > 0) { reqSub = oriObj.ReqVacationSubs.Single(r => r.Id == v.Id); } else { reqSub = new ReqVacationSub(); reqSub.FormNo = oriObj.FormNo; oriObj.ReqVacationSubs.Add(reqSub); } reqSub.PreStartTime = v.PreStartTime; reqSub.PreEndTime = v.PreEndTime; reqSub.Remarks = v.Remarks; } //更新时删除之前的签核数据 var list = from r in ctx.SignFlows where r.FormNo == obj.FormNo select r; ctx.SignFlows.DeleteAllOnSubmit(list); ctx.SubmitChanges(); rdto.Message = "更新成功"; rdto.Result = true; } catch (Exception ex) { rdto.Message = "更新失败"; rdto.Result = false; } if (obj.StatusId == 1)//写签核流程 { try { FlowSet fs = new FlowSet(); EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo; fs.SetSignFlow(obj.FormNo, ebi); rdto.Message = "更新且提交成功"; } catch (Exception ex) { rdto.Message = "表单已保存,但提交签核失败"; rdto.Result = false; } } return Json(rdto); }
partial void DeleteReqVacationSub(ReqVacationSub instance);
partial void InsertReqVacationSub(ReqVacationSub instance);
partial void UpdateReqVacationSub(ReqVacationSub instance);
private void detach_ReqVacationSubs(ReqVacationSub entity) { this.SendPropertyChanging(); entity.ReqVacationMain = null; }