Beispiel #1
0
        public void AddAccountAndContact(AddAccountAndContact AddAccountAndContact)
        {
            PDH_CrmService.CrmInterface.AccountOperation accountOp = new PDH_CrmService.CrmInterface.AccountOperation();
            AddAccountAndContactResponse response = accountOp.AddAccountAndContact(AddAccountAndContact);

            //return response;
        }
Beispiel #2
0
        log4net.ILog log = log4net.LogManager.GetLogger("fileLog");//获取一个日志记录器
        public AddAccountAndContactResponse AddAccountAndContact(AddAccountAndContact AddAccountAndContact)
        {
            log.Info("调用AddAccountAndContact接口。");
            AddAccountAndContactResponse response = new AddAccountAndContactResponse();
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                //1.Create Contact
                Entity contact = new Entity("contact");
                log.Info("request的值为:" + AddAccountAndContact.ToString());
                //if (AddAccountAndContact != null) {
                //    log.Info("request is not null");
                //    log.Info(AddAccountAndContact);
                //    foreach (System.Reflection.PropertyInfo p in AddAccountAndContact.GetType().GetProperties())
                //    {
                //        log.Info("Name:"+p.Name+"--Value:"+p.GetValue(AddAccountAndContact));
                //    }
                //}
                contact["firstname"]                = AddAccountAndContact.ContFirstName;
                contact["lastname"]                 = AddAccountAndContact.ContLastName;
                contact["emailaddress1"]            = AddAccountAndContact.ContEmail;
                contact["telephone1"]               = AddAccountAndContact.ContTelephone1;
                contact["address1_line1"]           = AddAccountAndContact.ContStreet1;
                contact["address1_line2"]           = AddAccountAndContact.ContStreet2;
                contact["address1_city"]            = AddAccountAndContact.ContCity;
                contact["address1_stateorprovince"] = AddAccountAndContact.ContStateProvince;
                contact["address1_country"]         = AddAccountAndContact.ContCountryRegion;
                contact["address1_postalcode"]      = AddAccountAndContact.ContZIPPostalCode;

                Guid contactId = organizationProxy.Create(contact);
                log.Info("创建contact成功:" + contactId.ToString());
                //2.Create Account
                Entity account = new Entity("account");
                account["name"]                     = AddAccountAndContact.AccAccountName;
                account["telephone1"]               = AddAccountAndContact.AccPhone;
                account["fax"]                      = AddAccountAndContact.AccFax;
                account["emailaddress1"]            = AddAccountAndContact.AccEmail;
                account["address1_line1"]           = AddAccountAndContact.AccStreet1;
                account["address1_line2"]           = AddAccountAndContact.AccStreet2;
                account["address1_city"]            = AddAccountAndContact.AccCity;
                account["address1_stateorprovince"] = AddAccountAndContact.AccStateProvince;
                account["address1_country"]         = AddAccountAndContact.AccCountryRegion;
                account["address1_postalcode"]      = AddAccountAndContact.AccZIPPostalCode;
                if (AddAccountAndContact.AccNewsletter == "0")
                {
                    account["new_newslettersubscribe"] = false;
                }
                else if (AddAccountAndContact.AccNewsletter == "1")
                {
                    account["new_newslettersubscribe"] = true;
                }

                account["primarycontactid"] = new EntityReference("contact", contactId);

                Guid accountId = organizationProxy.Create(account);
                log.Info("创建account成功:" + accountId.ToString());

                //update contact company..
                UpdateContactCompany(contactId, accountId);

                response.AccountId = accountId.ToString();
                response.ErrCode   = "0";
                return(response);
            }
            catch (Exception ex) {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }