0

The new Web API "stuff" looks great. I will be re-writing the foundation of my site into an API, but have a couple scenarios that I've got concern with.

Is it a bad idea to have an action that looks something like:

GetProducts(long memberId, string categories, int minPrice, int maxPrice, ...)

Where each variable is something the product can be filtered by. If the variable is null/empty it wouldn't use them to build the query.

Or is there another technique for reaching the same goal?

1 Answer 1

1

You could use a view model:

public class FilterViewModel
{
    public long MemberId { get; set; }
    public string Categories { get; set; }
    public int MinPrice { get; set; }
    public int MaxPrice { get; set; }
    ...
}

and then:

public IEnumerable<ProductViewModel> GetProducts(FilterViewModel filter)
{
    ...    
}
Sign up to request clarification or add additional context in comments.

1 Comment

I would make the primitive properties of the View Model nullable like code public int? MinPrice { get; set; } code, so that it is easier with optional values.

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.