Web API Controller POST Request LINQ search through String Array



I have the following database structure.

structure

Sorry for the horrible MS Paint Work

I am using .NET Framework 4.6.1 Web API Controller using Entity Framework.

My API Controller handles a post request that receives a structure similar to:

{  "countryCode": "CA", "languageCode": "EN ","partTypes":
"Brakes", "partComponents": "Relay" }

^^ Above request should find Part ID = 1 , and I want to select Part Request URL

{ "countryCode": "US","languageCode": "EN ","partTypes": "
Brakes , Clutch", "partComponents": "Relay"}

^^ Above request should find Part ID = 1 & 2 , and I want to select Part Request URL for both.

“Clutch, Resistor, EN, US” Should find Part ID = 2 etc.

My Question is how am I able to use LINQ to SQL or <IQueryable> to return the part ID for whatever post request is captured by the controller. The current code I have been working on so far looks similar to this:

Inside API Controller:

public string Post(PostProfile postProfile) 
string[] partURLArray;
{
using (var context = new context())
{partURLArray = context.ViewName
.Where(fields = >
field.CountryCode.Contains(postProfile.countryCode)
.Where(fields =>
fields.LanguageCode.Contains(postProfile.languageCode)
.Select(fields => fields.PartRequestURL).ToArray();
}
foreach 
(var part in partURLArray)
{
//do some stuff
}
return partString
}

Post Profile Model Class:

    public string countryCode { get; set; }
    public string languageCode { get; set; }
    public string[] partType { get; set; }
    public string[] partComponents { get; set; }

Related to : Web API Controller POST Request LINQ search through String Array

Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .