public HttpResponseMessage PostPurchasesToXero(SearchFilter searchFilter)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                try
                {
                    var purchases = context.XEROPurchases(searchFilter.StartDate, searchFilter.EndDate);
                    foreach (var purchase in purchases)
                    {
                        PurchaseToInvoiceViewModelConverter purchaseConverter = new PurchaseToInvoiceViewModelConverter();
                        try
                        {
                            InvoiceViewModel invoiceViewModel = purchaseConverter.Convert(purchase);
                            purchasesToPostList.Add(invoiceViewModel);
                        }
                        catch (InvoiceValidationException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message);
                        }
                        catch (SupplierDoesNotExistException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message);
                        }
                    }
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    ModelStateDictionary dictionary = errorStringConvertor.Convert("To many Purchases in daterange");
                    return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                }
            }
            try
            {
                xeroLogic.ExportInvoices(purchasesToPostList);
            }
            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 GetPurchases(SearchFilter searchFilter)
        {
            List<PurchaseViewModel> resultList = new List<PurchaseViewModel>();
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                try
                {
                    var purchases = context.XEROPurchases(searchFilter.StartDate, searchFilter.EndDate);

                    foreach (var purchase in purchases)
                    {
                        PurchaseViewModel purchaseViewModel = new PurchaseViewModel()
                        {
                            InvoiceNumber = purchase.InvoiceNumber,
                            EmailAddress = purchase.EmailAddress,
                            Address1 = purchase.POAddressLine1,
                            Address2 = purchase.POAddressLine2,
                            Address3 = purchase.POAddressLine3,
                            Address4 = purchase.POAddressLine4,
                            City = purchase.POCity,
                            Region = purchase.PORegion,
                            Country = purchase.POCountry,
                            PostalCode = purchase.POPostalCode,
                            InvoiceDate = purchase.InvoiceDate.GetValueOrDefault().ToString("dd-MM-yy"),
                            DueDate = purchase.DueDate.GetValueOrDefault().ToString("dd-MM-yy"),
                            InventoryItemCode = purchase.InventoryItemCode.ToString(),
                            Description = purchase.Description,
                            Quantity = purchase.Quantity.ToString(),
                            UnitAmount = purchase.UnitAmount.ToString(),
                            AccountCode = purchase.AccountCode.ToString(),
                            TaxType = purchase.TaxType,
                            TrackingName = purchase.TrackingName1,
                            TrackingOption = purchase.TrackingOption1,
                            Currency = purchase.Currency,

                        };

                        try
                        {
                            purchaseViewModel.ContactName = getSupplierName(purchase.ContactName);
                        }
                        catch(PurchaseValidationException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }
                        catch (SupplierDoesNotExistException e )
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);
                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }

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

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