EventDay / Infusionsoft.net

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

CustomField in Tables #16

Open UserSud opened 10 years ago

UserSud commented 10 years ago

Hi I hope you can help me with this. I've added a Yes/No CustomField: "Imported" into Orders on Infusionsoft and have added _Imported into the the Job table entity. If I set the type as string and query like:

var vNewJobs = _client.DataService.Query<Job>(vPage, q => q.Add(x => x._Imported, "~null~"));

then I can get all the records that hasn't set a value to the field yet.

But once I try to query for data with value in the _Imported field I get the exception telling me the response is an integer where string is expected. So from this I'm guessing the Yes/No field is storing an int of 0 or 1 so if I change the _Imported field type to int and query like:

var vNewJobs = _client.DataService.Query<Job>(vPage, q => q.Add(x => x._Imported, 1));

I get the results I need. The problem is what field type should I set the CustomField _Imported to if I wish to query for both null records and int records? I've tried the int? type with a null parameter but that didn't work.

Hope you can point me in the right direction,

many thanks! Sid

UserSud commented 10 years ago

Hi

what do you think about adding a check for null in the QueryBuilder Add like:

public IQueryBuilder<T> Add<TV>(Expression<Func<T, TV>> expression, TV value, ValuePosition valuePosition)
        {
            string name = Express.PropertyWithLambda(expression).Name;

            if (value == null)
            {
                _dictionary.Add(name, BuildPositionalValue(valuePosition, "~null~"));
            }
            else
            {
                _dictionary.Add(name, BuildPositionalValue(valuePosition, value));    
            }

            return this;
        }

I added an int? property to cater for a custom field I added to Orders and am thinking to make your table classes to be Partial then I'll extend the entities without affecting the generated codes. Do you think this is viable?

Thanks

trbngr commented 10 years ago

Hi UserSud,

I sincerely apologize for not responding earlier. I've been extremely busy lately.

I think the partial class is a good extension point! Let it rip!

I'll be back to try and fix some issues with the code when I get a chance. In the meantime, I encourage you to fork this repo, if you haven't yet, and have fun with it.

Thanks, Chris