public int Create(BrokenDeviceRequest o) { using (var db = new BillingDbContext()) { db.ServiceRequests.Add(o); return(db.SaveChanges()); } }
/****************************************************************************************** * From value object to domain model ******************************************************************************************/ public BrokenDeviceRequest ToRequest(BrokenDeviceRequestDTO vo) { var o = new BrokenDeviceRequest(); ClassCopier.Instance.Copy(vo, o); if (vo.RequestInfo != null) { o.RequestInfo = ToRequestInfo(vo.RequestInfo); } if (vo.Routing != null) { o.Routing = ToRoutingInfo(vo.Routing); } return(o); }
/****************************************************************************************** * From domain model to value object ******************************************************************************************/ public BrokenDeviceRequestDTO ToRequestDTO(BrokenDeviceRequest o) { var vo = new BrokenDeviceRequestDTO(); ClassCopier.Instance.Copy(o, vo); if (o.RequestInfo != null) { vo.RequestInfo = ToRequestInfoDTO(o.RequestInfo); } if (o.Routing != null) { vo.Routing = ToRoutingInfoDTO(o.Routing); } return(vo); }
public int Update(BrokenDeviceRequest o) { using (var db = new BillingDbContext()) { var ori = Select(o.No, true); 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.Routing != null) { var ri1 = o.Routing; if (ri1.No == 0) { ori.Routing = ri1; db.Entry(ri1).State = EntityState.Added; } else { ClassCopier.Instance.Copy(ri1, ori.Routing); db.Entry(ori.Routing).State = EntityState.Modified; if (ri1.Routings.Count > 0) { var list2 = ri1.Routings; foreach (var ri2 in list2) { if (ri2.No == 0) { ori.Routing.Routings.Add(ri2); db.Entry(ri1).State = EntityState.Added; } else { var oriri = ori.Routing.Routings.Find(x => x.No == ri2.No); db.RoutingItems.Attach(oriri); db.Entry(oriri).CurrentValues.SetValues(ri2); db.Entry(oriri).State = EntityState.Modified; } } } if (ri1.Contract != null) { var ct = ri1.Contract; if (ct.No == 0) { ori.Routing.Contract = ct; db.Entry(ct).State = EntityState.Added; } else { db.Contracts.Attach(ori.Routing.Contract); db.Entry(ori.Routing.Contract).CurrentValues.SetValues(ct); db.Entry(ori.Routing.Contract).State = EntityState.Modified; } } } } db.Entry(o).State = EntityState.Modified; return(db.SaveChanges()); } }