private Banckle.Person OutlookToBanckleContact(Outlook.ContactItem contact)
        {
            Banckle.Person person = new Banckle.Person();
            Banckle.Email[] emails = new Email[3];
            Banckle.Phone[] phone = new Banckle.Phone[15];
            Banckle.Address[] address = new Banckle.Address[4];

            try
            {
                person.birthDay = String.IsNullOrWhiteSpace(contact.Birthday.ToString("dd:MM:yyyy")) ? "" : contact.Birthday.ToString("dd:MM:yyyy");
                person.firstName = String.IsNullOrWhiteSpace(contact.FirstName) ? "" : contact.FirstName;
                person.lastName = String.IsNullOrEmpty(contact.LastName) ? "" : contact.LastName;
                //person.lastName = "";

                /*
                 * Emails
                 */

                emails[0] = new Email { type = "Primary", address = contact.Email1Address };
                emails[1] = new Email { type = "Secondary", address = contact.Email2Address };
                emails[2] = new Email { type = "Tertiary", address = contact.Email3Address };

                /*
                 * Phone Numbers
                 */

                phone[0] = new Phone { type = "Business2TelephoneNumber", number = contact.Business2TelephoneNumber };
                phone[1] = new Phone { type = "BusinessFaxNumber", number = contact.BusinessFaxNumber };
                phone[2] = new Phone { type = "BusinessTelephoneNumber", number = contact.BusinessTelephoneNumber };
                phone[3] = new Phone { type = "CallbackTelephoneNumber", number = contact.CallbackTelephoneNumber };
                phone[4] = new Phone { type = "CarTelephoneNumber", number = contact.CarTelephoneNumber };
                phone[5] = new Phone { type = "AssistantTelephoneNumber", number = contact.AssistantTelephoneNumber };
                phone[6] = new Phone { type = "CompanyMainTelephoneNumber", number = contact.CompanyMainTelephoneNumber };
                phone[7] = new Phone { type = "Home2TelephoneNumber", number = contact.Home2TelephoneNumber };
                phone[8] = new Phone { type = "HomeFaxNumber", number = contact.HomeFaxNumber };
                phone[9] = new Phone { type = "HomeTelephoneNumber", number = contact.HomeTelephoneNumber };
                phone[10] = new Phone { type = "MobileTelephoneNumber", number = contact.MobileTelephoneNumber };
                phone[11] = new Phone { type = "OtherFaxNumber", number = contact.OtherFaxNumber };
                phone[12] = new Phone { type = "OtherTelephoneNumber", number = contact.OtherTelephoneNumber };
                phone[13] = new Phone { type = "PrimaryTelephoneNumber", number = contact.PrimaryTelephoneNumber };
                phone[14] = new Phone { type = "RadioTelephoneNumber", number = contact.RadioTelephoneNumber };

                /*
                 * addresses
                 */

                address[0] = new Address { type = "Mailing", building = contact.MailingAddress, street = contact.MailingAddressStreet, city = contact.MailingAddressCity, state = contact.MailingAddressState, zip = contact.MailingAddressPostalCode, country = contact.MailingAddressCountry };
                address[1] = new Address { type = "Home", building = contact.HomeAddress, street = contact.HomeAddressStreet, city = contact.HomeAddressCity, state = contact.HomeAddressState, zip = contact.HomeAddressPostalCode, country = contact.HomeAddressCountry };
                address[2] = new Address { type = "Business", building = contact.BusinessAddress, street = contact.BusinessAddressStreet, city = contact.BusinessAddressCity, state = contact.BusinessAddressState, zip = contact.BusinessAddressPostalCode, country = contact.BusinessAddressCountry };
                address[3] = new Address { type = "Other", building = contact.OtherAddress, street = contact.OtherAddressStreet, city = contact.OtherAddressCity, state = contact.OtherAddressState, zip = contact.OtherAddressPostalCode, country = contact.OtherAddressCountry };

                person.emails = emails;
                person.phones = phone;
                person.addresses = address;

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("The new contact was not saved, because \r" + ex.Message + "\r" + ex.StackTrace);
            }
            return person;
        }
Exemplo n.º 2
0
        private Banckle.Person OutlookToBanckleContact(Outlook.ContactItem contact)
        {
            Banckle.Person    person  = new Banckle.Person();
            Banckle.Email[]   emails  = new Email[3];
            Banckle.Phone[]   phone   = new Banckle.Phone[15];
            Banckle.Address[] address = new Banckle.Address[4];

            try
            {
                person.birthDay  = String.IsNullOrWhiteSpace(contact.Birthday.ToString("dd:MM:yyyy")) ? "" : contact.Birthday.ToString("dd:MM:yyyy");
                person.firstName = String.IsNullOrWhiteSpace(contact.FirstName) ? "" : contact.FirstName;
                person.lastName  = String.IsNullOrEmpty(contact.LastName) ? "" : contact.LastName;
                //person.lastName = "";

                /*
                 * Emails
                 */

                emails[0] = new Email {
                    type = "Primary", address = contact.Email1Address
                };
                emails[1] = new Email {
                    type = "Secondary", address = contact.Email2Address
                };
                emails[2] = new Email {
                    type = "Tertiary", address = contact.Email3Address
                };

                /*
                 * Phone Numbers
                 */

                phone[0] = new Phone {
                    type = "Business2TelephoneNumber", number = contact.Business2TelephoneNumber
                };
                phone[1] = new Phone {
                    type = "BusinessFaxNumber", number = contact.BusinessFaxNumber
                };
                phone[2] = new Phone {
                    type = "BusinessTelephoneNumber", number = contact.BusinessTelephoneNumber
                };
                phone[3] = new Phone {
                    type = "CallbackTelephoneNumber", number = contact.CallbackTelephoneNumber
                };
                phone[4] = new Phone {
                    type = "CarTelephoneNumber", number = contact.CarTelephoneNumber
                };
                phone[5] = new Phone {
                    type = "AssistantTelephoneNumber", number = contact.AssistantTelephoneNumber
                };
                phone[6] = new Phone {
                    type = "CompanyMainTelephoneNumber", number = contact.CompanyMainTelephoneNumber
                };
                phone[7] = new Phone {
                    type = "Home2TelephoneNumber", number = contact.Home2TelephoneNumber
                };
                phone[8] = new Phone {
                    type = "HomeFaxNumber", number = contact.HomeFaxNumber
                };
                phone[9] = new Phone {
                    type = "HomeTelephoneNumber", number = contact.HomeTelephoneNumber
                };
                phone[10] = new Phone {
                    type = "MobileTelephoneNumber", number = contact.MobileTelephoneNumber
                };
                phone[11] = new Phone {
                    type = "OtherFaxNumber", number = contact.OtherFaxNumber
                };
                phone[12] = new Phone {
                    type = "OtherTelephoneNumber", number = contact.OtherTelephoneNumber
                };
                phone[13] = new Phone {
                    type = "PrimaryTelephoneNumber", number = contact.PrimaryTelephoneNumber
                };
                phone[14] = new Phone {
                    type = "RadioTelephoneNumber", number = contact.RadioTelephoneNumber
                };

                /*
                 * addresses
                 */

                address[0] = new Address {
                    type = "Mailing", building = contact.MailingAddress, street = contact.MailingAddressStreet, city = contact.MailingAddressCity, state = contact.MailingAddressState, zip = contact.MailingAddressPostalCode, country = contact.MailingAddressCountry
                };
                address[1] = new Address {
                    type = "Home", building = contact.HomeAddress, street = contact.HomeAddressStreet, city = contact.HomeAddressCity, state = contact.HomeAddressState, zip = contact.HomeAddressPostalCode, country = contact.HomeAddressCountry
                };
                address[2] = new Address {
                    type = "Business", building = contact.BusinessAddress, street = contact.BusinessAddressStreet, city = contact.BusinessAddressCity, state = contact.BusinessAddressState, zip = contact.BusinessAddressPostalCode, country = contact.BusinessAddressCountry
                };
                address[3] = new Address {
                    type = "Other", building = contact.OtherAddress, street = contact.OtherAddressStreet, city = contact.OtherAddressCity, state = contact.OtherAddressState, zip = contact.OtherAddressPostalCode, country = contact.OtherAddressCountry
                };

                person.emails    = emails;
                person.phones    = phone;
                person.addresses = address;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("The new contact was not saved, because \r" + ex.Message + "\r" + ex.StackTrace);
            }
            return(person);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="person"></param>
        /// <returns></returns>
        public string UpdatePerson(Person person)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            // Deserialize
            string DATA = serializer.Serialize(person);

            json = bancklePUTRequest(banckleCRMAPIUrl + "contacts/person/" + person.id + "?format=json", APIKey, Token, DATA);

            //var deserializedResult = serializer.Deserialize<List<Person>>(serializedResult);
            //ContactDetails contactDetails = serializer.Deserialize<ContactDetails>(json);
            return json;
        }