public static Xero.Api.Core.Model.Contact getXeroContact(string contactxeroid) { XeroCoreApi xeroapp = getxeroapp(); Xero.Api.Core.Model.Contact Xcontact = xeroapp.Contacts.Find(new Guid(contactxeroid)); return(Xcontact); }
private Invoice Given_an_invoice(InvoiceType type = InvoiceType.AccountsPayable, InvoiceStatus status = InvoiceStatus.Authorised, decimal amount = 100m, string accountCode = "100", Contact contact = null) { if (contact == null) contact = new Contact {Name = "ABC Bank"}; return Api.Create(new Invoice { Contact = contact, Type = type, Date = DateTime.UtcNow, DueDate = DateTime.UtcNow.AddDays(90), LineAmountTypes = LineAmountType.Inclusive, Status = status, LineItems = new List<LineItem> { new LineItem { AccountCode = "200", Description = "Good value item 1", LineAmount = 100m }, new LineItem { AccountCode = "200", Description = "Good value item 2", LineAmount = 100m } } }); }
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"; }
public static string updateorcreatexeroinvoice(InvoiceReadOnly Uinvoice, string clientxeroid) { XeroCoreApi xeroapp = getxeroapp(); Xero.Api.Core.Model.Invoice Xinvoice = new Xero.Api.Core.Model.Invoice(); Xinvoice.Number = Uinvoice.Number; Xero.Api.Core.Model.Contact Xcontact = xeroapp.Contacts.Find(new Guid(clientxeroid)); Xinvoice.Contact = Xcontact; Xinvoice.Date = Convert.ToDateTime(Uinvoice.CreatedDate); Xinvoice.Type = Xero.Api.Core.Model.Types.InvoiceType.AccountsReceivable; Xinvoice.LineAmountTypes = Xero.Api.Core.Model.Types.LineAmountType.Inclusive; Xinvoice.Status = Xero.Api.Core.Model.Status.InvoiceStatus.Authorised; Xinvoice.DueDate = Convert.ToDateTime(Uinvoice.DueDate); List <LineItem> Xiilist = new List <LineItem>(); foreach (InvoiceItemReadOnly uii in Uinvoice.Items) { Xero.Api.Core.Model.LineItem xii = new Xero.Api.Core.Model.LineItem(); xii.Quantity = Convert.ToDecimal(uii.Quantity); xii.Description = uii.Label; xii.UnitAmount = Convert.ToDecimal(uii.Price); xii.LineAmount = Convert.ToDecimal(uii.Total); xii.AccountCode = "200"; Xiilist.Add(xii); } Xinvoice.LineItems = Xiilist; Xero.Api.Core.Model.Invoice Xinvoicereturned = xeroapp.Update(Xinvoice); UnmsInvoice UXinvoice = new UnmsInvoice(); InvoiceAttribute newUcrmAttribute = new InvoiceAttribute() { CustomAttributeId = UNMSHelper.getcustomattributeid("xeroIdinvoice"), Value = Xinvoicereturned.Id.ToString() }; List <InvoiceAttribute> newlistattributes = new List <InvoiceAttribute>(); newlistattributes.Add(newUcrmAttribute); UXinvoice.attributes = newlistattributes; HTTPHelper.httpPatch("invoices" + "/" + Uinvoice.Id, UXinvoice); return(Xinvoice.Id.ToString()); }
public async Task update_contact() { var id = (await Given_a_contact()).Id; var changes = new Contact { Id = id, ContactNumber = "ID001" + Guid.NewGuid().ToString("N"), Name = "ABC Limited " + Guid.NewGuid().ToString("N"), FirstName = "John", LastName = "Smith", EmailAddress = "*****@*****.**", BankAccountDetails = "01-0123-0123456-00", TaxNumber = "12-345-678", AccountsReceivableTaxType = "OUTPUT", AccountsPayableTaxType = "INPUT", DefaultCurrency = "NZD", Addresses = new List<Address> { new Address { AddressType = AddressType.PostOfficeBox, AddressLine1 = "P O Box 123", City = "Wellington", PostalCode = "6011" } } }; var updated = await Api.UpdateAsync(changes); Assert.IsTrue(updated.Name.StartsWith("ABC")); Assert.IsTrue(updated.ContactNumber.StartsWith("ID001")); Assert.AreEqual("John", updated.FirstName); Assert.AreEqual("Smith", updated.LastName); Assert.AreEqual("*****@*****.**", updated.EmailAddress); Assert.AreEqual("01-0123-0123456-00", updated.BankAccountDetails); Assert.AreEqual("NZD", updated.DefaultCurrency); Assert.AreEqual("Wellington", updated.Addresses.Single(p => p.AddressType == AddressType.PostOfficeBox).City); }
// Generate Contact Id private string GenerateContactId(Contact c) { Contact result = new Contact(); try { result = _api.Create(c); } catch (Exception ex) { throw ex; } return result.Id.ToString(); }
public Task<Contact> CreateAsync(Contact item) { return Contacts.CreateAsync(item); }
public Task<Contact> UpdateAsync(Contact item) { return Contacts.UpdateAsync(item); }
// Update Contact by Id private bool UpdateContactAddress(string contactId,Address address) { bool isUpdated = true; Contact result = new Contact(); try { result = _api.Contacts.Find(new Guid(contactId)); result.Addresses.Add(address); _api.Contacts.Update(result); } catch (Exception ex) { isUpdated = false; // throw ex; } return isUpdated; }
//===================== Contact Operation ================ // Create Contact in Xero public string ContactCreate(Contact contact) { return GenerateContactId(contact); }
// Searching existed contact in Xero by Id private Contact GetContactById(string contactId) { Contact result = new Contact(); try { result = _api.Contacts.Find(new Guid(contactId)); } catch (Exception ex) { throw ex; } return result; }
//Check contact is existed in Xero private bool IsContactExist(string contactId) { bool isExistedContact = true; Contact result = new Contact(); try { result = _api.Contacts.Find(new Guid(contactId)); isExistedContact = !string.IsNullOrEmpty(result.Name); } catch (Exception ex) { isExistedContact = false; //throw ex; } return isExistedContact; }
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; }
public Contact Create(Contact item) { return Contacts.Create(item); }
protected async Task Given_a_target_invoice(Contact contact = null) { TargetInvoice = await Given_an_invoice(InvoiceType.AccountsReceivable, contact: contact); }
protected void Given_a_target_invoice(Contact contact = null) { TargetInvoice = Given_an_invoice(InvoiceType.AccountsReceivable, contact: contact); }
public static string updateorcreatexerocontact(ClientReadOnly UClient, string clientxeroid) { XeroCoreApi xeroapp = getxeroapp(); Contact contact = new Contact(); if (clientxeroid != "") { contact = getXeroContact(clientxeroid); } if (UClient.CompanyName != "") { contact.Name = UClient.CompanyName; contact.FirstName = UClient.CompanyContactFirstName; contact.LastName = UClient.CompanyContactLastName; } else { contact.Name = UClient.FirstName + " " + UClient.LastName; contact.FirstName = UClient.FirstName; contact.LastName = UClient.LastName; } List <Phone> phonesl = new List <Phone>(); if (UClient.Contacts.FirstOrDefault().Phone != null) { Phone phn1 = new Phone(); phn1.PhoneType = Xero.Api.Core.Model.Types.PhoneType.Mobile; phn1.PhoneNumber = UClient.Contacts.FirstOrDefault().Phone; phonesl.Add(phn1); } contact.Phones = phonesl; List <Address> addl = new List <Address>(); Address add = new Address(); add.AddressType = Xero.Api.Core.Model.Types.AddressType.PostOfficeBox; add.AddressLine1 = UClient.Street1; add.AddressLine2 = UClient.Street2; add.City = UClient.City; add.PostalCode = UClient.ZipCode; addl.Add(add); contact.Addresses = addl; contact.EmailAddress = UClient.Contacts.FirstOrDefault().Email; Xero.Api.Core.Model.Contact contactreturned = xeroapp.Update(contact); // now update the crm with the xeroid if (clientxeroid == "") { UnmsClient UXClient = new UnmsClient(); ClientAttribute newUcrmAttribute = new ClientAttribute() { CustomAttributeId = 1, Value = contactreturned.Id.ToString() }; List <ClientAttribute> newlistattributes = new List <ClientAttribute>(); newlistattributes.Add(newUcrmAttribute); UXClient.attributes = newlistattributes; HTTPHelper.httpPatch("clients" + "/" + UClient.Id, UXClient); } return(contactreturned.Id.ToString()); }
public Contact Update(Contact item) { return Contacts.Update(item); }
public ContactViewModel Convert(Contact contactToConvert) { ContactViewModel contactViewModel = new ContactViewModel(); contactViewModel.accountNumber = contactToConvert.AccountNumber; foreach (var address in contactToConvert.Addresses) { if(address.AddressType == Xero.Api.Core.Model.Types.AddressType.Street) { contactViewModel.address1 = address.AddressLine1; contactViewModel.address2 = address.AddressLine2; contactViewModel.address3 = address.AddressLine3; contactViewModel.addressType = "STREET"; contactViewModel.city = address.City; contactViewModel.postalcode = address.PostalCode; contactViewModel.region = address.Region; } } if (contactToConvert.ContactPersons.Count > 0) { if (contactToConvert.ContactPersons.FirstOrDefault().LastName == null) { contactViewModel.contactName = contactToConvert.ContactPersons.FirstOrDefault().FirstName; } else { contactViewModel.contactName = contactToConvert.ContactPersons.FirstOrDefault().FirstName + contactToConvert.ContactPersons.FirstOrDefault().LastName; } } contactViewModel.defaultCurrency = contactToConvert.DefaultCurrency; contactViewModel.email = contactToConvert.EmailAddress; foreach (var phoneNumber in contactToConvert.Phones) { if (phoneNumber.PhoneType == Xero.Api.Core.Model.Types.PhoneType.Fax) { contactViewModel.faxNumber = phoneNumber.PhoneNumber; } else if (phoneNumber.PhoneType == Xero.Api.Core.Model.Types.PhoneType.Mobile) { contactViewModel.mobileNumber = phoneNumber.PhoneNumber; } else if (phoneNumber.PhoneType == Xero.Api.Core.Model.Types.PhoneType.Default) { contactViewModel.phone = phoneNumber.PhoneNumber; } } contactViewModel.sname = contactToConvert.LastName; contactViewModel.fname = contactToConvert.FirstName; contactViewModel.name = contactToConvert.Name; contactViewModel.xeroContactId = contactToConvert.Id.ToString(); if (contactToConvert.ContactStatus == Xero.Api.Core.Model.Status.ContactStatus.Archived) { contactViewModel.isArchived = true; } return contactViewModel; }