private ContactViewModel getContact(string supplierName)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                var supplier = (from sp in context.SUPPLIERs
                                where sp.ext_key1 == supplierName
                                select sp).SingleOrDefault();

                if (!(string.IsNullOrEmpty(supplier.ext_key)))
                {
                    ConvertSupplierToContactViewModel contactConvertor = new ConvertSupplierToContactViewModel();
                    ContactViewModel contactViewModel = contactConvertor.Convert(supplier);

                    return contactViewModel;
                }
                else
                {
                    throw new SupplierDoesNotExistException("The supplier " + supplierName + " is bounded to a purchase but does not exist in Xero. Please make sure that the supplier exist in Xero");
                }

            }
        }
        public HttpResponseMessage PostSuppliersToXero(List<string> supplierCodeList)
        {
            using (DataClassesDataContext context = new DataClassesDataContext())
            {
                var supplierResult = (from sp in context.SUPPLIERs
                                      where supplierCodeList.Contains(sp.supplier1)
                                      select sp).ToList();

                foreach (var supplier in supplierResult)
                {
                    if (!(supplier == null))
                    {
                        ConvertSupplierToContactViewModel contactConvertor = new ConvertSupplierToContactViewModel();
                        ContactViewModel contactViewModel;
                        try
                        {
                            contactViewModel = contactConvertor.Convert(supplier);
                        }
                        catch (NotVailidEmailException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);

                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }
                        catch (SupplierNameAlreadyExistException e)
                        {
                            ModelStateDictionary dictionary = errorStringConvertor.Convert(e.Message);

                            return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                        }

                        if (DoesSupplierExistInXeroContacts(supplier.supplier1))
                        {
                            contactsToUpdateList.Add(contactViewModel);
                        }
                        else
                        {
                            contactsToCreateList.Add(contactViewModel);
                        }

                    }
                }

                if (contactsToCreateList.Count > 0 && contactsToUpdateList.Count > 0)
                {
                    return exportToXero(xeroAction.CREATE_AND_UPDATE);
                }
                else if (contactsToCreateList.Count > 0)
                {
                    return exportToXero(xeroAction.CREATE);
                }
                else if (contactsToUpdateList.Count > 0)
                {
                    return exportToXero(xeroAction.UPDATE);
                }
                else
                {
                    string message = "There are no suppliers to update or create in Xero.";

                    ModelStateDictionary dictionary = errorStringConvertor.Convert(message);

                    return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, dictionary);
                }
            }
        }