0

In this question the Answer suggests using an object as the parameter. What URL would I use to access that? In the OP's first example, my original approach was to overload the action (not sure if overload is the right word) so I had:

public IEnumerable<NTOrder> Get()...

public IEnumerable<NTOrder> Get(int p)...

public IEnumerable<NTOrder> Get(int p, int q)

not elegant, I know, but if I change it to one object I don't know how to format the URL...

Old Code

public IEnumerable<NTOrder> Get() {
    //build NTOrderList
    return NTOrderList;
}

New Code

public class FilterView
{
    public int? fID { get; set; }
    public int? fCustomer { get; set; }
    public string fSalesPerson{ get; set; }
}

public IEnumerable<NTOrder> Get(FilterView queryFilter) {
    //build NTOrderList
    List<NTOrder> result = (from order in NTOrderList
                               where (order.OrderID == queryFilter.fID || queryFilter.fID == null)
                                  && (order.CustomerID == queryFilter.fCustomer || queryFilter.fCustomer == null)
                                  && (queryFilter.fSalesPerson == null || order.Salesperson.Equals(queryFilter.fSalesPerson))
                                select order).ToList();

    return result;
}

2 Answers 2

1

I found this answer as a possible solution, which basically suggests passing the data as JSON in the url and adding a filter to convert that to a complex object, but as the OP in that post suggests it's not the most elegant way...anybody have a more elegant solution?

Sign up to request clarification or add additional context in comments.

Comments

0

The URL would work in exactly the same way, with one querystring parameter for each property in the object.

2 Comments

I tried that...I get an exception message: No MediaTypeFormatter is available to read an object of type 'FilterView' from content with media type ''undefined''.
I've posted my old & new code snippets...the old url was just localhost:3495/api/NTOrder. For the new code I've tried various things such as localhost:3495/api/NTOrder?fID=101 and other combinations with all/no variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.