public void CheckRefundedCustomerPDT(int customerId, CustomerSuccessfulPDT e, SidejobEntities context)
 {
     //Check to see if exist
     var r = (from c in context.RefundCustomerSuccessfulPDTs
              where c.ProjectID == ProjectID && c.CustomerID == customerId
              select c).FirstOrDefault();
     if (r == null)
     {
         //Check if Record exist
         if ((from c in context.RefundCustomerSuccessfulPDTs
              where PDTID == e.PDTID
              select c).FirstOrDefault() == null)
         {
             //Insert the new refund from the successful table
             var refund = new RefundCustomerSuccessfulPDT
                              {
                                  PDTID = e.PDTID,
                                  GrossTotal = e.GrossTotal,
                                  Invoice = e.Invoice,
                                  PaymentStatus = e.PaymentStatus,
                                  FirstName = e.FirstName,
                                  LastName = e.LastName,
                                  PaymentFee = e.PaymentFee,
                                  BusinessEmail = e.BusinessEmail,
                                  TxToken = e.TxToken,
                                  ReceiverEmail = e.ReceiverEmail,
                                  ItemName = e.ItemName,
                                  CurrencyCode = e.CurrencyCode,
                                  TransactionId = e.TransactionId,
                                  Custom = e.Custom,
                                  subscriberId = e.subscriberId,
                                  CustomerID = e.CustomerID,
                                  ProjectID = e.ProjectID
                              };
             context.AddToRefundCustomerSuccessfulPDTs(refund);
             context.SaveChanges();
             PDTID = e.PDTID;
         }
     }
 }
    public void CheckCustomerArchivedPDT(int customerId, SidejobEntities context)
    {
        //Check ArchivedSuccessful PDT
        var e1 = (from c in context.ArchivedCustomerSuccessfulPDTs
                  where c.CustomerID == customerId && c.ProjectID == ProjectID
                  select c).FirstOrDefault();
        if (e1 != null)
        {
            var transaction = e1.TransactionId;
            //Insert the new refund from archieved table

            //Check if Transaction exist in Refund
            var exist = (from c in context.RefundCustomerSuccessfulPDTs
                         where c.TransactionId == transaction
                         select c).FirstOrDefault();
            if (exist == null)
            {
                //Check if Transaction exist in ArchivedRefund
                var existarchived = (from c in context.ArchivedRefundCustomerSuccessfulPDTs
                                     where c.TransactionId == transaction
                                     select c).FirstOrDefault();

                if (existarchived == null)
                {
                    //Check if Record exist
                    if ((from c in context.RefundCustomerSuccessfulPDTs
                         where PDTID == e1.PDTID
                         select c).FirstOrDefault() == null)
                    {
                        //Insert the new record
                        var archivedrefund = new RefundCustomerSuccessfulPDT
                                                 {
                                                     PDTID = e1.PDTID,
                                                     GrossTotal = e1.GrossTotal,
                                                     Invoice = e1.Invoice,
                                                     PaymentStatus = e1.PaymentStatus,
                                                     FirstName = e1.FirstName,
                                                     LastName = e1.LastName,
                                                     PaymentFee = e1.PaymentFee,
                                                     BusinessEmail = e1.BusinessEmail,
                                                     TxToken = e1.TxToken,
                                                     ReceiverEmail = e1.ReceiverEmail,
                                                     ItemName = e1.ItemName,
                                                     CurrencyCode = e1.CurrencyCode,
                                                     TransactionId = e1.TransactionId,
                                                     Custom = e1.Custom,
                                                     subscriberId = e1.subscriberId,
                                                     CustomerID = e1.CustomerID,
                                                     ProjectID = e1.ProjectID
                                                 };
                        context.AddToRefundCustomerSuccessfulPDTs(archivedrefund);
                        context.SaveChanges();
                        PDTID = e1.PDTID;
                    }
                }
            }
        }
    }