Writing my first ASP.NET Web API web service. Still learing the power of Linq as well. I feel like there is a more ideomatic way of doing this:
public class StylesController : ApiController
{
private Entities db = new Entities();
// GET api/Styles
public IEnumerable<Style> GetStyles(int division = 0, int family = 0, int model = 0, int year = 0, string market = "ANY")
{
market = market.ToUpper(); // make sure market is upper case
IEnumerable<Style> q = db.Styles;
if (division > 0) { q = q.Where(s => s.DivisionId == division); }
if (family > 0) { q = q.Where(s => s.FamilyId == family); }
if (model > 0) { q = q.Where(s => s.ModelId == model); }
if (year > 0) { q = q.Where(s => s.Year == year); }
if (market != "ANY") { q = q.Where(s => s.MarketCode == market); }
return q.Distinct().OrderBy(s => s.Id).ToList();
}
}