public TFlow FlowSingle(string loginKey, ref ErrorInfo err, int?id) { using (DBEntities db = new DBEntities()) { var reEnt = new TFlow(); var ent = db.YL_FLOW.SingleOrDefault(x => x.ID == id); if (ent == null) { reEnt.FlowListStr = "[]"; reEnt.X_Y = "[]"; return(reEnt); } else { reEnt = Fun.ClassToCopy <YL_FLOW, ProInterface.Models.TFlow>(ent); foreach (var t in ent.YL_FLOW_FLOWNODE_FLOW.ToList()) { var flowEnt = Fun.ClassToCopy <YL_FLOW_FLOWNODE_FLOW, TFlowFlownodeFlow>(t); flowEnt.AllRoleIDList = t.YL_ROLE.Select(x => x.ID).ToList(); foreach (var roleID in flowEnt.AllRoleIDList) { flowEnt.AllRoleStr += "," + roleID; } if (flowEnt.AllRoleStr != null && flowEnt.AllRoleStr.Length > 1) { flowEnt.AllRoleStr = flowEnt.AllRoleStr.Substring(1); } reEnt.FlowList.Add(flowEnt); } reEnt.FlowListStr = JSON.DecodeToStr(reEnt.FlowList); reEnt.AllFlownode = db.YL_FLOW_FLOWNODE.ToList().Select(x => new SelectListItem { Text = x.NAME, Value = x.ID.ToString() }).ToList(); return(reEnt); } } }
public bool FlowSave(string loginKey, ref ErrorInfo err, TFlow ent) { using (DBEntities db = new DBEntities()) { ent.FlowList = JSON.EncodeToEntity <IList <TFlowFlownodeFlow> >(ent.FlowListStr); ent.Idxy = JSON.EncodeToEntity <IList <IdXY> >(ent.X_Y); if (string.IsNullOrEmpty(ent.FLOW_TYPE)) { ent.FLOW_TYPE = "默认"; } var useId = ent.FlowList.Select(x => x.FROM_FLOWNODE_ID).ToList(); foreach (var t in ent.FlowList) { if (!useId.Contains(t.TO_FLOWNODE_ID)) { useId.Add(t.TO_FLOWNODE_ID); } } ent.Idxy = ent.Idxy.Where(x => useId.Contains(x.Id)).ToList(); var flow = db.YL_FLOW.SingleOrDefault(x => x.ID == ent.ID); if (flow == null) { flow = Fun.ClassToCopy <TFlow, YL_FLOW>(ent); flow.ID = Fun.GetSeqID <YL_FLOW>(); db.YL_FLOW.Add(flow); } else { flow = Fun.ClassToCopy <TFlow, YL_FLOW>(ent, flow); } #region 除节点 foreach (var t in flow.YL_FLOW_FLOWNODE_FLOW.ToList()) { if (ent.FlowList.Where(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID).Count() == 0) { t.YL_ROLE.Clear(); db.YL_FLOW_FLOWNODE_FLOW.Remove(t); } } #endregion foreach (var t in ent.FlowList) { if (!string.IsNullOrEmpty(t.AllRoleStr)) { string[] tmpRoleArr = t.AllRoleStr.Trim().Split(','); if (tmpRoleArr.Length > 0) { t.AllRoleIDList = tmpRoleArr.Select(x => Convert.ToInt32(x)).ToList(); } } var thisFlow = flow.YL_FLOW_FLOWNODE_FLOW.SingleOrDefault(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID); if (thisFlow == null) { YL_FLOW_FLOWNODE_FLOW flowF = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t); flowF.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList(); flowF.ID = Fun.GetSeqID <YL_FLOW_FLOWNODE_FLOW>(); flowF.FLOW_ID = flow.ID; db.YL_FLOW_FLOWNODE_FLOW.Add(flowF); } else { thisFlow = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t, thisFlow); thisFlow.YL_ROLE.Clear(); thisFlow.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList(); thisFlow = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t); } } try { db.SaveChanges(); } catch (DbEntityValidationException e) { err.IsError = true; err.Message = Fun.GetDbEntityErrMess(e); return(false); } catch (Exception e) { err.IsError = true; err.Message = Fun.GetExceptionMessage(e); return(false); } } return(true); }