private void CreatePaymentsInDatabase(List<Payment> paymentsToUpdate)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                List<XERO_PAYMENT> xeroPayments = new List<XERO_PAYMENT>();
                foreach (var payment in paymentsToUpdate)
                {
                    XERO_PAYMENT xeroPayment = new XERO_PAYMENT();
                    xeroPayment.AccountCode = payment.Account.Code;
                    xeroPayment.Amount = payment.Amount;
                    xeroPayment.CurrencyRate = payment.CurrencyRate;
                    xeroPayment.Date = payment.Date;
                    xeroPayment.InvoiceNumber = payment.Invoice.Number;
                    xeroPayment.IsReconciled = payment.IsReconciled;
                    xeroPayment.PaymentStatus = payment.Status.ToString();
                    xeroPayment.PaymentType = payment.Type.ToString();
                    xeroPayment.Reference = payment.Reference;
                    xeroPayment.XeroId = payment.Id.ToString();
                    xeroPayment.UpdateDate = payment.UpdatedDateUtc.GetValueOrDefault();

                    xeroPayments.Add(xeroPayment);
                }

                context.XERO_PAYMENTs.InsertAllOnSubmit(xeroPayments);
                context.SubmitChanges();
            }
        }
        private void UpdatePaymentsInDatabase(List<Payment> paymentsToUpdate)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                List<XERO_PAYMENT> xeroPayments = new List<XERO_PAYMENT>();
                foreach (var payment in paymentsToUpdate)
                {
                    var originalPayment = (from xm in context.XERO_PAYMENTs
                                           where xm.XeroId == payment.Id.ToString()
                                           select xm).FirstOrDefault();

                    originalPayment.AccountCode = payment.Account.Code;
                    originalPayment.Amount = payment.Amount;
                    originalPayment.CurrencyRate = payment.CurrencyRate;
                    originalPayment.Date = payment.Date;
                    originalPayment.InvoiceNumber = payment.Invoice.Number;
                    originalPayment.IsReconciled = payment.IsReconciled;
                    originalPayment.PaymentStatus = payment.Status.ToString();
                    originalPayment.PaymentType = payment.Type.ToString();
                    originalPayment.Reference = payment.Reference;
                    originalPayment.XeroId = payment.Id.ToString();
                    originalPayment.UpdateDate = payment.UpdatedDateUtc.GetValueOrDefault();

                    xeroPayments.Add(originalPayment);
                }

                context.SubmitChanges();
            }
        }