示例#1
0
        public ContactItem importContact(ContactItem contactItem)
        {
            try
            {
                ContactApi contactApi         = new ContactApi(session.GetApiClient());
                List <ImportUserRecord> users = new List <ImportUserRecord>();
                ImportUserRecord        user  = new ImportUserRecord();
                user.FirstName = contactItem.Name;
                user.Email     = contactItem.Email;
                user.Phone     = contactItem.Phone;
                users.Add(user);

                ImportAcquaintancesInput  input  = new ImportAcquaintancesInput(users);
                ImportAcquaintancesResult result = contactApi.ImportAcquaintances(input);
                if (result.Hdr.Rc == 0)
                {
                    List <ImportUserRecord> failedUsers = result.FailedUsers;
                    if (failedUsers.Count > 0)
                    {
                        throw new Exception("Error importing user");
                    }
                    else
                    {
                        return(searchUserByEmail(contactItem.Email));
                    }
                }
                else
                {
                    throw new Exception("Error importing contact");
                }
            } catch (Exception ex)
            {
                throw new Exception("Error importing contact", ex);
            }
        }