EventDay / Infusionsoft.net

A C# Wrapper around the Infusionsoft.com API
16 stars 22 forks source link

Cannot add company with CompanyName #9

Open mrmoses opened 11 years ago

mrmoses commented 11 years ago

Adding a company with a CompanyName results in this error:

Server returned a fault exception: [10] [NoFieldFound]No field found: Company.CompanyName

The correct field name is "Company", which is what is set as the XmlRpcMember for the CompanyName field in the Company class, but it doesn't seem to get passed as "Company" in the XmlRpc call.

Changing CompanyName field to Company results in a compile error (which I assume is why the field is CompanyName to begin with):

member names cannot be the same as their enclosing type

A workaround is to use

client.DataService.Add("Company", XmlRpcStruct)

http://community.infusionsoft.com/showthread.php/4101-Cannot-add-a-Company-to-InfusionSoft-when-passing-CompanyName

seancroxford commented 9 years ago

If you are trying to add a company using this method:

CompanyID = client.DataService.Add<InfusionSoft.Tables.Company>(setter =>
{
    setter.Set(c => c.CompanyName, "Company Name");
});

Then you can modify the Support/FieldSetter.cs class and replace the set method with this:

public virtual IFieldSetter<T> Set<TV>(Expression<Func<T, TV>> expression, TV value)
{
    PropertyInfo property = Express.PropertyWithLambda(expression);

    var attributes = property.GetCustomAttributes(typeof(XmlRpcMemberAttribute), false);

    string ColName = property.Name;

    if (attributes.Any())
    {
        var attribute = attributes.Cast<XmlRpcMemberAttribute>().First();
        if (!String.IsNullOrEmpty(attribute.Member) && attribute.Member != property.Name)
        {
            ColName = attribute.Member;
        }
    }

    _dictionary.Add(ColName, value);
    return this;
}

This will basically use the XmlRpcMember atribute set on the class in /Tables/Company.cs