public HttpResponseMessage PostPaymentsToXero(SearchFilter searchFilter)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                try
                {
                    var payments = context.XEROPayments(searchFilter.StartDate, searchFilter.EndDate);
                    foreach (var payment in payments)
                    {
                        PaymentToInvoiceViewModelConverter invoiceConverter = new PaymentToInvoiceViewModelConverter();
                        try
                        {
                            InvoiceViewModel invoiceViewModel = invoiceConverter.Convert(payment);
                            invoicesToPostList.Add(invoiceViewModel);
                        }
                        catch (InvoiceValidationException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }
                        catch (CustomerDoesNotExistException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }
                    }
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    ModelStateDictionary dictionary = errorStringConvertor.Convert("To many invoices in daterange");
                    return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                }
            }
            try
            {
                xeroLogic.ExportInvoices(invoicesToPostList);
            }
            catch (XeroApiLimitException e)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                return this.Request.CreateErrorResponse(HttpStatusCode.BadGateway, dictionary);
            }
            catch (XeroException e)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
            }
            catch (XeroApiValidationException e)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
            }
            catch (Exception)
            {
                ModelStateDictionary dictionary = errorStringConvertor.Convert("Something went wrong. Please check the data and try again.");
                return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, dictionary);
            }

            return this.Request.CreateResponse(HttpStatusCode.OK);
        }
        public HttpResponseMessage GetPayment(SearchFilter searchFilter)
        {
            List<PaymentViewModel> resultList = new List<PaymentViewModel>();
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                try
                {
                    var payments = context.XEROPayments(searchFilter.StartDate, searchFilter.EndDate);

                    foreach (var payment in payments)
                    {
                        PaymentViewModel paymentViewModel = new PaymentViewModel()
                        {
                            InvoiceNumber = payment.InvoiceNumber,
                            ContactName = payment.ContactName,
                            Email = payment.EmailAddress,
                            Address1 = payment.POAddressLine1,
                            Address2 = payment.POAddressLine2,
                            Address3 = payment.POAddressLine3,
                            City = payment.POCity,
                            Region = payment.PORegion,
                            Country = payment.POCountry,
                            PostalCode = payment.POPostalCode,
                            InvoiceDate = payment.InvoiceDate.GetValueOrDefault().ToString("dd-MM-yy"),
                            DueDate = payment.DueDate.GetValueOrDefault().ToString("dd-MM-yy"),
                            InventoryItemCode = payment.InventoryItemCode.ToString(),
                            Description = payment.Description,
                            Quantity = payment.Quantity.ToString(),
                            UnitAmount = payment.UnitAmount.ToString(),
                            Discount = payment.Discount.ToString(),
                            AccountCode = payment.AccountCode.ToString(),
                            TaxType = payment.TaxType,
                            TrackingName = payment.TrackingName1,
                            TrackingOption = payment.TrackingOption1,
                            Reference = payment.Reference,
                            BrandingTheme = payment.BrandingTheme
                        };

                        resultList.Add(paymentViewModel);
                    }
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    ModelStateDictionary dictionary = errorStringConvertor.Convert("To many payments in daterange");
                    return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                }

                return this.Request.CreateResponse(HttpStatusCode.OK, resultList);
            }
        }