private void btnContact_Click(object sender, EventArgs e) { var contactWatch = Stopwatch.StartNew(); _api = new APICore() { UserAgent = "3D safety Xero Demo" }; Contact user = new Contact(); user.Addresses = new List<Address>(); user.Phones = new List<Phone>(); //Phone Phone userPhone = new Phone(); userPhone.PhoneType = PhoneType.Default; userPhone.PhoneNumber = txtPhoneNumber.Text; user.Phones.Add(userPhone); //Personal detail user.FirstName = txtFirstName.Text; user.LastName = txtLastName.Text; user.Name = txtCompanyName.Text; user.EmailAddress = txtEmailAddress.Text; XeroAPI xeroapi = new XeroAPI(api); txtContactId.Text= xeroapi.ContactCreate(user); contactWatch.Stop(); lblContactTime.Text = "Execute time: " + contactWatch.Elapsed.TotalSeconds.ToString()+ "s"; }
/*This Function Create a New Contact in the Xero System */ public void CreateXeroContact(String CompanyName, String WebSite, bool primary, DeltoneCompany delComPany) { Xero.Api.Core.Model.Phone tele = new Xero.Api.Core.Model.Phone(); tele.PhoneType = PhoneType.Default; tele.PhoneAreaCode = delComPany.DefaultAreaCode; tele.PhoneCountryCode = "+61"; tele.PhoneNumber = delComPany.DefaultNumber; Xero.Api.Core.Model.Phone mobile = new Xero.Api.Core.Model.Phone(); mobile.PhoneType = PhoneType.Mobile; // mobile.PhoneAreaCode = delComPany.DefaultAreaCode; mobile.PhoneCountryCode = "+61"; mobile.PhoneNumber = delComPany.MobileNumber; List <Xero.Api.Core.Model.Phone> del_phones = new List <Xero.Api.Core.Model.Phone>(); del_phones.Add(tele); del_phones.Add(mobile); XeroCoreApi private_user = CreateAPI(); var Contact = private_user.Create(new Xero.Api.Core.Model.Contact { Name = delComPany.CompanyName, Website = delComPany.CompanyWebSite, Phones = del_phones, }); }
public Contact Convert(ContactViewModel contactViewModel) { Contact contact = new Contact(); Address address = new Address(); address.AddressLine1 = contactViewModel.address1; address.AddressLine2 = contactViewModel.address2; address.AddressLine3 = contactViewModel.address3; address.City = contactViewModel.city; address.PostalCode = contactViewModel.postalcode; address.Region = contactViewModel.region; if (contactViewModel.addressType == "STREET") { address.AddressType = AddressType.Street; } List<Address> addressList = new List<Address>(); addressList.Add(address); Phone phone = new Phone { PhoneType = Xero.Api.Core.Model.Types.PhoneType.Default, PhoneNumber = contactViewModel.phone }; Phone fax = new Phone { PhoneType = Xero.Api.Core.Model.Types.PhoneType.Fax, PhoneNumber = contactViewModel.faxNumber }; Phone mobile = new Phone { PhoneType = Xero.Api.Core.Model.Types.PhoneType.Mobile, PhoneNumber = contactViewModel.mobileNumber }; List<Phone> phones = new List<Phone>(); phones.Add(phone); phones.Add(fax); phones.Add(mobile); DateTime now = DateTime.Now; if (!(contactViewModel.contactName == null)) { string[] splitedContactPerson = contactViewModel.contactName.Split(' '); string contactPersonLastName; ContactPerson contactPerson = new ContactPerson(); if (splitedContactPerson.Count() > 0 && (!(string.IsNullOrEmpty(splitedContactPerson[0])))) { contactPerson.FirstName = splitedContactPerson[0]; if (splitedContactPerson.Count() > 1) { contactPersonLastName = ""; for (int i = 1; i < splitedContactPerson.Count(); i++) { contactPersonLastName += splitedContactPerson[i]; } contactPerson.LastName = contactPersonLastName; } } if (!(string.IsNullOrEmpty(contactPerson.FirstName))) { List<ContactPerson> contactPersonList = new List<ContactPerson>(); contactPersonList.Add(contactPerson); contact.ContactPersons = contactPersonList; } } if (String.IsNullOrEmpty(contactViewModel.defaultCurrency)) { contact.DefaultCurrency = "NZD"; } else { contact.DefaultCurrency = contactViewModel.defaultCurrency; } if (contactViewModel.isArchived == true) { contact.ContactStatus = ContactStatus.Archived; } else { contact.ContactStatus = ContactStatus.Active; } if (!(String.IsNullOrEmpty(contactViewModel.xeroContactId))) { contact.Id = Guid.Parse(contactViewModel.xeroContactId); } if (!(string.IsNullOrEmpty(contactViewModel.name.Trim()))) { contact.Name = contactViewModel.name; } else { if (!(string.IsNullOrEmpty(contactViewModel.accountNumber.Trim()))) { throw new ContactWithNoFNameSnameOrNameException("The name of contact with accountNumber " + contactViewModel.accountNumber + "is empty."); } else { throw new ContactWithNoFNameSnameOrNameException("The name of a contact can not be empty."); } } contact.AccountNumber = contactViewModel.accountNumber; contact.EmailAddress = contactViewModel.email; contact.FirstName = contactViewModel.fname; contact.LastName = contactViewModel.sname; contact.Addresses = addressList; contact.Phones = phones; contact.UpdatedDateUtc = now; return contact; }