In my Application there are 4 dropdowns(family,class,series,Fusebody) and one search button. I have to search product table based on selections of these Dropdowns. This search can be done using any one dropdown value from that 4 dropdowns or multiple. Like below i have tried.
Example: from one dropdown selection
[Route("api/KendoCascading/GetclRes/{cres}")]
public HttpResponseMessage GetclRes(string cres)
{
using (CrossReferenceTool1Entities cp = new CrossReferenceTool1Entities())
{
var query = (from u in cp.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && u.Class.Contains(cres)) select u).Distinct().ToList();
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
}
example: two different dropdown selection
[Route("api/KendoCascading/GetresClsbyFam/{cres}/{family}")]
public HttpResponseMessage GetresClsbyFam(string cres,int family)
{
var query = (from u in ep.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && u.Class.Contains(cres) && u.ProductFMSFamiliesID==family) select u).ToList();
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
example: three dropdowns selection
[Route("api/KendoCascading/Getfaclapp/{family}/{cres}/{apRes}")]
public HttpResponseMessage Getfaclapp(int family, string cres, string apRes)
{
using (CrossReferenceTool1Entities al = new CrossReferenceTool1Entities())
{
var query = (from u in al.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && u.Class.Contains(cres) && u.ProductFMSFamiliesID==family && al.ProductApplications.Any(d=>d.ProductCode.Contains(u.ProductCode) && d.ProductApplicationName.Contains(apRes))) select u).ToList();
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
}
Like this i have routed the api methods so far. But there are so many combinations to route. If its possible to add parameters based on conditions like below:
[Route("api/KendoCascading/GetResultByAll/{family}/{cres}/{apps}/{seID}")]
public HttpResponseMessage GetResultByAll(int family,string cres,string apps, int seID)
{
if(family==0)
{
result=query1;
}
if(family==0 && cres==null)
{
result=query2;
}
}
Like that. I have tried but in web api route its showing error. It is not taking any null values. How to do that?