public int Delete(string id)
 {
     using (var db = new BillingDbContext())
     {
         var o = Select(id, true);
         if (o.RequestInfo != null)
         {
             var ri = o.RequestInfo;
             db.Entry(ri).State = EntityState.Deleted;
         }
         if (o.Routings.Count > 0)
         {
             var list1 = o.Routings;
             foreach (var ri1 in list1)
             {
                 db.Entry(ri1).State = EntityState.Deleted;
                 if (ri1.Contract != null)
                 {
                     var c = ri1.Contract;
                     db.Entry(c).State = EntityState.Deleted;
                 }
                 if (ri1.Routings.Count > 0)
                 {
                     var list2 = ri1.Routings;
                     foreach (var ri2 in list2)
                     {
                         db.Entry(ri2).State = EntityState.Deleted;
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Deleted;
         return(db.SaveChanges());
     }
 }
 public ErrorChargesRequest Select(string id, bool all = false)
 {
     using (var db = new BillingDbContext())
     {
         if (all)
         {
             var sql1 = from o in db.ServiceRequests.OfType <ErrorChargesRequest>()
                        .Include(o => o.RequestInfo)
                        .Include(o => o.Routing).Include(o => o.Routing.Contracts)
                        .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                        select o;
             var req = sql1.SingleOrDefault();
             if (req != null && req.Routing.Contracts.Count > 0)
             {
                 foreach (var cwb in req.Routing.Contracts)
                 {
                     ContractWithBillings cwb1 = cwb;
                     var sql2 = from c in db.Contracts.OfType <ContractWithBillings>().Include(c => c.Billings)
                                where c.No == cwb1.No
                                select c;
                     cwb1 = sql2.SingleOrDefault();
                 }
             }
             return(req);
         }
         var sql = from o in db.ServiceRequests.OfType <ErrorChargesRequest>()
                   .Include(o => o.RequestInfo)
                   .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                   select o;
         return(sql.SingleOrDefault());
     }
 }
Beispiel #3
0
 public int Delete(string id)
 {
     using (var db = new BillingDbContext())
     {
         return(db.SaveChanges());
     }
 }
 public TerminationRequest Select(string id, bool all = false)
 {
     using (var db = new BillingDbContext())
     {
         if (all)
         {
             var sql1 = from o in db.ServiceRequests.OfType <TerminationRequest>()
                        .Include(o => o.RequestInfo).Include(o => o.RequestInfo.Terminations)
                        .Include(o => o.Routing).Include(o => o.Routing.Terminations)
                        .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                        select o;
             var req = sql1.SingleOrDefault();
             if (req != null && req.Routing.Terminations.Count > 0)
             {
                 foreach (var ti in req.Routing.Terminations)
                 {
                     TerminationItem ti1  = ti;
                     var             sql2 = from t in db.Terminations.Include(t => t.TerminatedContract)
                                            where t.No == ti1.No
                                            select t;
                     ti1 = sql2.SingleOrDefault();
                 }
             }
             return(req);
         }
         var sql = from o in db.ServiceRequests.OfType <TerminationRequest>()
                   .Include(o => o.RequestInfo)
                   .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                   select o;
         return(sql.SingleOrDefault());
     }
 }
 public NewScenarioRequest Select(string id, bool all = false)
 {
     using (var db = new BillingDbContext())
     {
         if (all)
         {
             var sql1 = from o in db.ServiceRequests.OfType <NewScenarioRequest>()
                        .Include(o => o.RequestInfo)
                        .Include(o => o.Routings)
                        .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                        select o;
             var req = sql1.SingleOrDefault();
             if (req != null && req.Routings.Count > 0)
             {
                 foreach (var ri in req.Routings)
                 {
                     NewScenarioRoutingInfo ri1 = ri;
                     var sql2 = from r in db.RoutingInfos.OfType <NewScenarioRoutingInfo>()
                                .Include(r => r.Contract)
                                .Include(r => r.Routings).Where(r => r.No == ri1.No)
                                select r;
                     ri1 = sql2.SingleOrDefault();
                 }
             }
             return(req);
         }
         var sql = from o in db.ServiceRequests.OfType <NewScenarioRequest>()
                   .Include(o => o.RequestInfo)
                   .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                   select o;
         return(sql.SingleOrDefault());
     }
 }
 public int Delete(long no)
 {
     using (var db = new BillingDbContext())
     {
         var o = Select(no, true);
         if (o.RequestInfo != null)
         {
             var ri = o.RequestInfo;
             db.Entry(ri).State = EntityState.Deleted;
         }
         if (o.Routing != null)
         {
             var ri1 = o.Routing;
             db.Entry(ri1).State = EntityState.Deleted;
             if (ri1.Contracts.Count > 0)
             {
                 var list1 = ri1.Contracts;
                 foreach (var cwb in list1)
                 {
                     db.Entry(cwb).State = EntityState.Deleted;
                     if (cwb.Billings.Count > 0)
                     {
                         var list2 = cwb.Billings;
                         foreach (var cb in list2)
                         {
                             db.Entry(cb).State = EntityState.Deleted;
                         }
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Deleted;
         return(db.SaveChanges());
     }
 }
Beispiel #7
0
 public UserAndRole SelectByUsername(string username)
 {
     using (var db = new BillingDbContext())
     {
         var sql = from o in db.UserRoles where o.Username == username select o;
         return(sql.SingleOrDefault());
     }
 }
 public int Create(NewScenarioRequest o)
 {
     using (var db = new BillingDbContext())
     {
         db.ServiceRequests.Add(o);
         return(db.SaveChanges());
     }
 }
Beispiel #9
0
 public int Create(TransferAssetRequest o)
 {
     using (var db = new BillingDbContext())
     {
         db.ServiceRequests.Add(o);
         return(db.SaveChanges());
     }
 }
 public int Create(TerminationRequest o)
 {
     using (var db = new BillingDbContext())
     {
         db.ServiceRequests.Add(o);
         return(db.SaveChanges());
     }
 }
 public int Delete(string id)
 {
     using (var db = new BillingDbContext())
     {
         var o = Select(id, true);
         if (o.RequestInfo != null)
         {
             var ri = o.RequestInfo;
             db.Entry(ri).State = EntityState.Deleted;
         }
         if (o.Routings.Count > 0)
         {
             var list1 = o.Routings;
             foreach (var ri1 in list1)
             {
                 db.Entry(ri1).State = EntityState.Deleted;
                 if (ri1.GetType() == typeof(NewContractExtLineRoutingInfo))
                 {
                     var ri2 = ri1 as NewContractExtLineRoutingInfo;
                     if (ri2 != null && ri2.Contract != null)
                     {
                         var ct = ri2.Contract;
                         db.Entry(ct).State = EntityState.Deleted;
                     }
                 }
                 else if (ri1.GetType() == typeof(NewContractIpPhoneRoutingInfo))
                 {
                     var ri2 = ri1 as NewContractIpPhoneRoutingInfo;
                     if (ri2 != null && ri2.Contract != null)
                     {
                         var ct = ri2.Contract;
                         db.Entry(ct).State = EntityState.Deleted;
                     }
                 }
                 else if (ri1.GetType() == typeof(NewContractLaptopRoutingInfo))
                 {
                     var ri2 = ri1 as NewContractLaptopRoutingInfo;
                     if (ri2 != null && ri2.Contract != null)
                     {
                         var ct = ri2.Contract;
                         db.Entry(ct).State = EntityState.Deleted;
                     }
                 }
                 else if (ri1.GetType() == typeof(NewContractSoftwareRoutingInfo))
                 {
                     var ri2 = ri1 as NewContractSoftwareRoutingInfo;
                     if (ri2 != null && ri2.Contract != null)
                     {
                         var ct = ri2.Contract;
                         db.Entry(ct).State = EntityState.Deleted;
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Deleted;
         return(db.SaveChanges());
     }
 }
Beispiel #12
0
 public InvoiceProformaHeader SelectByQueryParam(string soldToParty,
                                                 DateTime startDate, DateTime endDate, bool billingBlock = false,
                                                 bool reasonForRejection = false)
 {
     using (var db = new BillingDbContext())
     {
         return(null);
     }
 }
Beispiel #13
0
 public long Create(UserAndRole o)
 {
     using (var db = new BillingDbContext())
     {
         db.Entry(o).State = EntityState.Added;
         db.SaveChanges();
         return(o.No);
     }
 }
Beispiel #14
0
 public long Create(InvoiceProformaHeader o)
 {
     using (var db = new BillingDbContext())
     {
         db.InvoiceProformaHeaders.Add(o);
         db.SaveChanges();
         return(o.No);
     }
 }
Beispiel #15
0
 public long Delete(long id)
 {
     using (var db = new BillingDbContext())
     {
         var o = db.UserRoles.Find(id);
         if (o != null)
         {
             db.Entry(o).State = EntityState.Deleted;
         }
         return(db.SaveChanges());
     }
 }
 public int Delete(long no)
 {
     using (var db = new BillingDbContext())
     {
         var o = Select(no, true);
         if (o.RequestInfo != null)
         {
             var ri = o.RequestInfo;
             db.Entry(ri).State = EntityState.Deleted;
             if (ri.Terminations.Count > 0)
             {
                 var list1 = ri.Terminations;
                 foreach (var ti in list1)
                 {
                     db.Entry(ti).State = EntityState.Deleted;
                 }
             }
         }
         if (o.Routing != null)
         {
             var ri = o.Routing;
             db.Entry(ri).State = EntityState.Deleted;
             if (ri.Routings.Count() > 0)
             {
                 var list = ri.Routings;
                 foreach (var ri1 in list)
                 {
                     db.Entry(ri1).State = EntityState.Deleted;
                 }
             }
             if (ri.Terminations.Count > 0)
             {
                 var list2 = ri.Terminations;
                 foreach (var ti in list2)
                 {
                     db.Entry(ti).State = EntityState.Deleted;
                     if (ti.TerminatedContract != null)
                     {
                         var tc = ti.TerminatedContract;
                         db.Entry(tc).State = EntityState.Deleted;
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Deleted;
         return(db.SaveChanges());
     }
 }
Beispiel #17
0
 public TransferAssetRequest Select(string id, bool all = false)
 {
     using (var db = new BillingDbContext())
     {
         if (all)
         {
             var sql1 = from o in db.ServiceRequests.OfType <TransferAssetRequest>()
                        .Include(o => o.RequestInfo)
                        .Include(o => o.Routings)
                        .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                        select o;
             var req = sql1.SingleOrDefault();
             if (req != null && req.Routings.Count > 0)
             {
                 foreach (var ri in req.Routings)
                 {
                     if (ri.GetType() == typeof(TransferAssetByHolderRoutingInfo))
                     {
                         var ri1  = ri as TransferAssetByHolderRoutingInfo;
                         var sql2 = from r in db.RoutingInfos.OfType <TransferAssetByHolderRoutingInfo>()
                                    .Include(r => r.NewContract).Include(r => r.OldContract).Include(r => r.Routings)
                                    .Where(r => r.No == ri1.No)
                                    select r;
                         ri1 = sql2.SingleOrDefault();
                     }
                     else if (ri.GetType() == typeof(TransferAssetByLocationRoutingInfo))
                     {
                         var ri1  = ri as TransferAssetByLocationRoutingInfo;
                         var sql2 = from r in db.RoutingInfos.OfType <TransferAssetByLocationRoutingInfo>()
                                    .Include(r => r.OldContract).Include(r => r.UpdContract).Include(r => r.Routings)
                                    .Where(r => r.No == ri1.No)
                                    select r;
                         ri1 = sql2.SingleOrDefault();
                     }
                 }
             }
             return(req);
         }
         var sql = from o in db.ServiceRequests.OfType <TransferAssetRequest>()
                   .Include(o => o.RequestInfo)
                   .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                   select o;
         return(sql.SingleOrDefault());
     }
 }
        public string NewServiceRequestId()
        {
            using (var db = new BillingDbContext())
            {
                var o = new Index();
                db.Indexes.Add(o);
                db.SaveChanges();

                var counter = "" + o.Counter;
                while (counter.Length < 13)
                {
                    counter = "0" + counter;
                }
                o.UniqueId        = "S-" + counter;
                db.Entry(o).State = EntityState.Modified;
                db.SaveChanges();
                return(o.UniqueId);
            }
        }
Beispiel #19
0
 public BrokenDeviceRequest Select(string id, bool all = false)
 {
     using (var db = new BillingDbContext())
     {
         if (all)
         {
             var sql1 = from o in db.ServiceRequests.OfType <BrokenDeviceRequest>()
                        .Include(o => o.RequestInfo)
                        .Include(o => o.Routing).Include(o => o.Routing.Contract)
                        .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                        select o;
             return(sql1.SingleOrDefault());
         }
         var sql = from o in db.ServiceRequests.OfType <BrokenDeviceRequest>()
                   .Include(o => o.RequestInfo)
                   .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                   select o;
         return(sql.SingleOrDefault());
     }
 }
 public int Update(NewScenarioRequest 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.Routings.Count > 0)
         {
             var list1 = o.Routings;
             foreach (var ri1 in list1)
             {
                 if (ri1.No == 0)
                 {
                     ori.Routings.Add(ri1);
                     db.Entry(ri1).State = EntityState.Added;
                 }
                 else
                 {
                     var oriri1 = ori.Routings.Find(x => x.No == ri1.No);
                     if (oriri1 != null)
                     {
                         db.RoutingInfos.Attach(oriri1);
                         ClassCopier.Instance.Copy(ri1, oriri1);
                         db.Entry(oriri1).State = EntityState.Modified;
                         if (ri1.Routings.Count > 0)
                         {
                             var list2 = ri1.Routings;
                             foreach (var ri2 in list2)
                             {
                                 if (ri2.No == 0)
                                 {
                                     oriri1.Routings.Add(ri2);
                                     db.Entry(ri2).State = EntityState.Added;
                                 }
                                 else
                                 {
                                     var oriri2 = oriri1.Routings.Find(y => y.No == ri2.No);
                                     db.RoutingItems.Attach(oriri2);
                                     db.Entry(oriri2).CurrentValues.SetValues(ri2);
                                     db.Entry(oriri2).State = EntityState.Modified;
                                 }
                             }
                         }
                         if (ri1.Contract != null)
                         {
                             var oc = ri1.Contract;
                             if (oc.No == 0)
                             {
                                 oriri1.Contract    = oc;
                                 db.Entry(oc).State = EntityState.Added;
                             }
                             else
                             {
                                 db.Entry(oriri1.Contract).CurrentValues.SetValues(oc);
                                 db.Entry(oriri1.Contract).State = EntityState.Modified;
                             }
                         }
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Modified;
         return(db.SaveChanges());
     }
 }
 public int Update(TerminationRequest 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);
                 ClassCopier.Instance.Copy(ri, ori.RequestInfo);
                 if (ri.Terminations.Count > 0)
                 {
                     var list1 = ri.Terminations;
                     foreach (var ti in list1)
                     {
                         if (ti.No == 0)
                         {
                             ori.RequestInfo.Terminations.Add(ti);
                             db.Entry(ti).State = EntityState.Added;
                         }
                         else
                         {
                             var list2 = ori.RequestInfo.Terminations;
                             var term  = list2.Find(x => x.No == ti.No);
                             db.Terminations.Attach(term);
                             db.Entry(term).CurrentValues.SetValues(ti);
                             db.Entry(term).State = EntityState.Modified;
                         }
                     }
                 }
             }
         }
         if (o.Routing != null)
         {
             var ri = o.Routing;
             if (ri.No == 0)
             {
                 ori.Routing        = ri;
                 db.Entry(ri).State = EntityState.Added;
             }
             else
             {
                 ClassCopier.Instance.Copy(o.Routing, ori.Routing);
                 db.Entry(ori.Routing).State = EntityState.Modified;
                 if (ri.Routings.Count > 0)
                 {
                     var list2 = ri.Routings;
                     foreach (var ri1 in list2)
                     {
                         if (ri1.No == 0)
                         {
                             ori.Routing.Routings.Add(ri1);
                             db.Entry(ri1).State = EntityState.Added;
                         }
                         else
                         {
                             var oriri = ori.Routing.Routings.Find(x => x.No == ri1.No);
                             db.RoutingItems.Attach(oriri);
                             db.Entry(oriri).CurrentValues.SetValues(ri1);
                             db.Entry(oriri).State = EntityState.Modified;
                         }
                     }
                 }
                 if (ri.Terminations.Count > 0)
                 {
                     var list3 = ri.Terminations;
                     foreach (var ti in list3)
                     {
                         if (ti.No == 0)
                         {
                             ori.Routing.Terminations.Add(ti);
                             db.Entry(ti).State = EntityState.Added;
                         }
                         else
                         {
                             var oriti = ori.Routing.Terminations.Find(y => y.No == ti.No);
                             db.Terminations.Attach(oriti);
                             if (ti.TerminatedContract != null)
                             {
                                 var tc = ti.TerminatedContract;
                                 if (tc.No == 0)
                                 {
                                     oriti.TerminatedContract = tc;
                                     db.Entry(tc).State       = EntityState.Added;
                                 }
                                 else
                                 {
                                     db.Entry(oriti.TerminatedContract).CurrentValues.SetValues(tc);
                                     db.Entry(tc).State = EntityState.Modified;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Modified;
         return(db.SaveChanges());
     }
 }
Beispiel #22
0
 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());
     }
 }
Beispiel #23
0
 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());
     }
 }
Beispiel #24
0
        public int Delete(string id)
        {
            using (var db = new BillingDbContext())
            {
                var o = Select(id, true);
                if (o.RequestInfo != null)
                {
                    var ri = o.RequestInfo;
                    db.Entry(ri).State = EntityState.Deleted;
                }
                if (o.Routings.Count > 0)
                {
                    var list1 = o.Routings;
                    foreach (var ri1 in list1)
                    {
                        db.Entry(ri1).State = EntityState.Deleted;
                        if (ri1.Routings.Count > 0)
                        {
                            var list2 = ri1.Routings;
                            foreach (var ri2 in list2)
                            {
                                db.Entry(ri2).State = EntityState.Deleted;
                            }
                        }

                        if (ri1.GetType() == typeof(TransferAssetByHolderRoutingInfo))
                        {
                            var ri3 = ri1 as TransferAssetByHolderRoutingInfo;
                            if (ri3 != null)
                            {
                                if (ri3.NewContract != null)
                                {
                                    var nc = ri3.NewContract;
                                    db.Entry(nc).State = EntityState.Deleted;
                                }
                                if (ri3.OldContract != null)
                                {
                                    var oc = ri3.OldContract;
                                    db.Entry(oc).State = EntityState.Deleted;
                                }
                            }
                        }
                        if (ri1.GetType() == typeof(TransferAssetByLocationRoutingInfo))
                        {
                            var ri3 = ri1 as TransferAssetByLocationRoutingInfo;
                            if (ri3 != null)
                            {
                                if (ri3.UpdContract != null)
                                {
                                    var nc = ri3.UpdContract;
                                    db.Entry(nc).State = EntityState.Deleted;
                                }
                                if (ri3.OldContract != null)
                                {
                                    var oc = ri3.OldContract;
                                    db.Entry(oc).State = EntityState.Deleted;
                                }
                            }
                        }
                    }
                }
                db.Entry(o).State = EntityState.Deleted;
                return(db.SaveChanges());
            }
        }
 public int Update(NewContractRequest 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.Routings.Count > 0)
         {
             var list1 = o.Routings;
             foreach (var ri1 in list1)
             {
                 if (ri1.No == 0)
                 {
                     ori.Routings.Add(ri1);
                     db.Entry(ri1).State = EntityState.Added;
                 }
                 else
                 {
                     var oriri = ori.Routings.Find(x => x.No == ri1.No);
                     if (oriri != null)
                     {
                         db.RoutingInfos.Attach(oriri);
                         ClassCopier.Instance.Copy(ri1, oriri);
                         db.Entry(oriri).State = EntityState.Modified;
                         if (ri1.Routings.Count > 0)
                         {
                             var list2 = ri1.Routings;
                             foreach (var ri2 in list2)
                             {
                                 if (ri2.No == 0)
                                 {
                                     oriri.Routings.Add(ri2);
                                     db.Entry(ri2).State = EntityState.Added;
                                 }
                                 else
                                 {
                                     var oriri2 = oriri.Routings.Find(y => y.No == ri2.No);
                                     db.RoutingItems.Attach(oriri2);
                                     db.Entry(oriri2).CurrentValues.SetValues(ri2);
                                     db.Entry(oriri2).State = EntityState.Modified;
                                 }
                             }
                         }
                         if (ri1.GetType() == typeof(NewContractExtLineRoutingInfo))
                         {
                             var oriri1 = oriri as NewContractExtLineRoutingInfo;
                             var ri2    = ri1 as NewContractExtLineRoutingInfo;
                             if (ri2 != null && ri2.Contract != null)
                             {
                                 if (oriri1 != null)
                                 {
                                     var ct = ri2.Contract;
                                     if (ct.No == 0)
                                     {
                                         oriri1.Contract    = ct;
                                         db.Entry(ct).State = EntityState.Added;
                                     }
                                     else
                                     {
                                         db.Entry(oriri1.Contract).CurrentValues.SetValues(ct);
                                         db.Entry(oriri1.Contract).State = EntityState.Modified;
                                     }
                                 }
                             }
                         }
                         else if (ri1.GetType() == typeof(NewContractIpPhoneRoutingInfo))
                         {
                             var oriri2 = oriri as NewContractIpPhoneRoutingInfo;
                             var ri3    = ri1 as NewContractIpPhoneRoutingInfo;
                             if (ri3 != null && ri3.Contract != null)
                             {
                                 if (oriri2 != null)
                                 {
                                     var ct = ri3.Contract;
                                     if (ct.No == 0)
                                     {
                                         oriri2.Contract    = ct;
                                         db.Entry(ct).State = EntityState.Added;
                                     }
                                     else
                                     {
                                         db.Entry(oriri2.Contract).CurrentValues.SetValues(ct);
                                         db.Entry(oriri2.Contract).State = EntityState.Modified;
                                     }
                                 }
                             }
                         }
                         else if (ri1.GetType() == typeof(NewContractLaptopRoutingInfo))
                         {
                             var oriri3 = oriri as NewContractLaptopRoutingInfo;
                             var ri4    = ri1 as NewContractLaptopRoutingInfo;
                             if (ri4 != null && ri4.Contract != null)
                             {
                                 if (oriri3 != null)
                                 {
                                     var ct = ri4.Contract;
                                     if (ct.No == 0)
                                     {
                                         oriri3.Contract    = ct;
                                         db.Entry(ct).State = EntityState.Added;
                                     }
                                     else
                                     {
                                         db.Entry(oriri3.Contract).CurrentValues.SetValues(ct);
                                         db.Entry(oriri3.Contract).State = EntityState.Modified;
                                     }
                                 }
                             }
                         }
                         else if (ri1.GetType() == typeof(NewContractSoftwareRoutingInfo))
                         {
                             var oriri4 = oriri as NewContractSoftwareRoutingInfo;
                             var ri5    = ri1 as NewContractSoftwareRoutingInfo;
                             if (ri5 != null && ri5.Contract != null)
                             {
                                 if (oriri4 != null)
                                 {
                                     var ct = ri5.Contract;
                                     if (ct.No == 0)
                                     {
                                         oriri4.Contract    = ct;
                                         db.Entry(ct).State = EntityState.Added;
                                     }
                                     else
                                     {
                                         db.Entry(oriri4.Contract).CurrentValues.SetValues(ct);
                                         db.Entry(oriri4.Contract).State = EntityState.Modified;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Modified;
         return(db.SaveChanges());
     }
 }
 public NewContractRequest Select(string id, bool all = false)
 {
     using (var db = new BillingDbContext())
     {
         if (all)
         {
             var sql1 = from o in db.ServiceRequests.OfType <NewContractRequest>()
                        .Include(o => o.RequestInfo)
                        .Include(o => o.Routings)
                        .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                        select o;
             var req = sql1.SingleOrDefault();
             if (req != null && req.Routings.Count > 0)
             {
                 foreach (var ri in req.Routings)
                 {
                     if (ri.GetType() == typeof(NewContractExtLineRoutingInfo))
                     {
                         var ri1  = ri as NewContractExtLineRoutingInfo;
                         var sql2 = from r in db.RoutingInfos.OfType <NewContractExtLineRoutingInfo>()
                                    .Include(r => r.Contract).Include(r => r.Routings)
                                    .Where(r => r.No == ri1.No)
                                    select r;
                         ri1 = sql2.SingleOrDefault();
                     }
                     else if (ri.GetType() == typeof(NewContractIpPhoneRoutingInfo))
                     {
                         var ri1  = ri as NewContractIpPhoneRoutingInfo;
                         var sql2 = from r in db.RoutingInfos.OfType <NewContractIpPhoneRoutingInfo>()
                                    .Include(r => r.Contract).Include(r => r.Routings)
                                    .Where(r => r.No == ri1.No)
                                    select r;
                         ri1 = sql2.SingleOrDefault();
                     }
                     else if (ri.GetType() == typeof(NewContractLaptopRoutingInfo))
                     {
                         var ri1  = ri as NewContractLaptopRoutingInfo;
                         var sql2 = from r in db.RoutingInfos.OfType <NewContractLaptopRoutingInfo>()
                                    .Include(r => r.Contract).Include(r => r.Routings)
                                    .Where(r => r.No == ri1.No)
                                    select r;
                         ri1 = sql2.SingleOrDefault();
                     }
                     else if (ri.GetType() == typeof(NewContractSoftwareRoutingInfo))
                     {
                         var ri1  = ri as NewContractSoftwareRoutingInfo;
                         var sql2 = from r in db.RoutingInfos.OfType <NewContractSoftwareRoutingInfo>()
                                    .Include(r => r.Contract).Include(r => r.Routings)
                                    .Where(r => r.No == ri1.No)
                                    select r;
                         ri1 = sql2.SingleOrDefault();
                     }
                 }
             }
             return(req);
         }
         var sql = from o in db.ServiceRequests.OfType <NewContractRequest>()
                   .Include(o => o.RequestInfo)
                   .Where(o => o.Id == id && o.State != EServiceRequestState.DELETED)
                   select o;
         return(sql.SingleOrDefault());
     }
 }