public int Create(TransferAssetRequest o) { using (var db = new BillingDbContext()) { db.ServiceRequests.Add(o); return(db.SaveChanges()); } }
/****************************************************************************************** * From domain model to value object ******************************************************************************************/ public TransferAssetRequestDTO ToRequestDTO(TransferAssetRequest o) { var vo = new TransferAssetRequestDTO(); ClassCopier.Instance.Copy(o, vo); if (o.RequestInfo != null) { vo.RequestInfo = ToRequestInfoDTO(o.RequestInfo); } if (o.Routings.Count > 0) { vo.Routings = ToRoutingInfosDTO(o.Routings); } return(vo); }
/****************************************************************************************** * From value object to domain model ******************************************************************************************/ public TransferAssetRequest ToRequest(TransferAssetRequestDTO vo) { var o = new TransferAssetRequest(); ClassCopier.Instance.Copy(vo, o); if (vo.RequestInfo != null) { o.RequestInfo = ToRequestInfo(vo.RequestInfo); } if (vo.Routings.Count > 0) { o.Routings = ToRoutingInfos(vo.Routings); } return(o); }
public int Update(TransferAssetRequest o) { using (var db = new BillingDbContext()) { var ori = Select(o.No, true); if (ori == null) { return(0); } if (o.RequestInfo != null) { var ri = o.RequestInfo; if (ri.No == 0) { ori.RequestInfo = ri; db.Entry(ri).State = EntityState.Added; } else { db.RequestInfos.Attach(ori.RequestInfo); db.Entry(ori.RequestInfo).CurrentValues.SetValues(ri); db.Entry(ori.RequestInfo).State = EntityState.Modified; } } if (o.Routings.Count > 0) { var list1 = o.Routings; foreach (var ri in list1) { if (ri.GetType() == typeof(TransferAssetByHolderRoutingInfo)) { var ri1 = ri as TransferAssetByHolderRoutingInfo; if (ri1 != null) { if (ri1.No == 0) { ori.Routings.Add(ri1); db.Entry(ri1).State = EntityState.Added; } else { var tahri = ori.Routings.Find(x => x.No == ri1.No) as TransferAssetByHolderRoutingInfo; if (tahri != null) { ClassCopier.Instance.Copy(ri1, tahri); //System.Diagnostics.Debug.WriteLine("1. TransferAssetByHolderRoutingInfo NO = " + tahri.No); db.RoutingInfos.Attach(tahri); if (ri1.NewContract != null) { var nc = ri1.NewContract; if (nc.No == 0) { tahri.NewContract = nc; db.Entry(tahri.NewContract).State = EntityState.Added; } else { db.Entry(tahri.NewContract).CurrentValues.SetValues(nc); db.Entry(tahri.NewContract).State = EntityState.Modified; } } if (ri1.OldContract != null) { var oc = ri1.OldContract; if (oc.No == 0) { tahri.OldContract = oc; db.Entry(tahri.OldContract).State = EntityState.Added; } else { db.Entry(tahri.OldContract).CurrentValues.SetValues(oc); db.Entry(tahri.OldContract).State = EntityState.Modified; } } if (ri1.Routings.Count > 0) { var list2 = ri1.Routings; //System.Diagnostics.Debug.WriteLine("1. INPUT WF ROUTING SIZE = " + list2.Count); foreach (var ri2 in list2) { if (ri2.No == 0) { tahri.Routings.Add(ri2); db.Entry(ri2).State = EntityState.Added; } else { //System.Diagnostics.Debug.WriteLine("1. LOADED WORKFLOW SIZE = " + tahri.Routings.Count); //System.Diagnostics.Debug.WriteLine("1. LOOKUP FOR WORKFLOW ROUTING NO = " + ri2.No); var oririw1 = tahri.Routings.Find(z => z.No == ri2.No); db.RoutingItems.Attach(oririw1); db.Entry(oririw1).CurrentValues.SetValues(ri2); db.Entry(oririw1).State = EntityState.Modified; } } } } } } } if (ri.GetType() == typeof(TransferAssetByLocationRoutingInfo)) { var ri3 = ri as TransferAssetByLocationRoutingInfo; if (ri3 != null) { if (ri3.No == 0) { ori.Routings.Add(ri3); db.Entry(ri3).State = EntityState.Added; } else { var talri = ori.Routings.Find(x => x.No == ri3.No) as TransferAssetByLocationRoutingInfo; if (talri != null) { ClassCopier.Instance.Copy(ri3, talri); //System.Diagnostics.Debug.WriteLine("2. TransferAssetByLocationRoutingInfo NO = " + talri.No); db.RoutingInfos.Attach(talri); if (ri3.UpdContract != null) { var nc = ri3.UpdContract; if (nc.No == 0) { talri.UpdContract = nc; db.Entry(talri.UpdContract).State = EntityState.Added; } else { db.Entry(talri.UpdContract).CurrentValues.SetValues(nc); db.Entry(talri.UpdContract).State = EntityState.Modified; } } if (ri3.OldContract != null) { var oc = ri3.OldContract; if (oc.No == 0) { talri.OldContract = oc; db.Entry(talri.OldContract).State = EntityState.Added; } else { db.Entry(talri.OldContract).CurrentValues.SetValues(oc); db.Entry(talri.OldContract).State = EntityState.Modified; } } if (ri3.Routings.Count > 0) { var list3 = ri3.Routings; //System.Diagnostics.Debug.WriteLine("2. INPUT WF ROUTING SIZE = " + list3.Count); foreach (var ri4 in list3) { if (ri4.No == 0) { talri.Routings.Add(ri4); db.Entry(ri4).State = EntityState.Added; } else { //System.Diagnostics.Debug.WriteLine("2. LOADED WORKFLOW SIZE = " + talri.Routings.Count); //System.Diagnostics.Debug.WriteLine("2. LOOKUP FOR WORKFLOW ROUTING NO = " + ri4.No); var oririw2 = talri.Routings.Find(z => z.No == ri4.No); db.RoutingItems.Attach(oririw2); db.Entry(oririw2).CurrentValues.SetValues(ri4); db.Entry(oririw2).State = EntityState.Modified; } } } } } } } } } db.Entry(ori).State = EntityState.Modified; return(db.SaveChanges()); } }