Web API Controller POST Request LINQ search through String Array


oferrer
24/4/2016 9:44 am
HOME » Web Development

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
Web API Controller POST Request LINQ search through String Array
24/4/2016 9:44 am Web Development

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; }

ASP.NET MVC submitting json array to controller as regular post request (nonajax)
Web Development

All the examples of json I can find online only show how to submit json arrays w/ the jquery command $.ajax(). I'm submitting some data from a custom user control as a json array. I was wondering if it's possible to submit a json array as a regular post request to the server (like a normal form) so the browser renders the page returned.


Controller:


[JsonFilter(Param = "record", JsonDataType = typeof(TitleViewModel))]
public ActionResult SaveTitle(TitleViewModel record)
{
// save the title.
return RedirectToAction("Index", new { titleId = tid });
}

Javascript:


<
Why do linq search has a huge difference in efficiency when I use string and array especially for large data?
12/11/2014 2:30 pm Web Development

I want to search the name of the students which contains the keywords,at first I pass the keywords separated by commas,but I find the search time is too long.But when I convert these keywords into an array,it is real fast.Why do linq search has a huge difference in efficiency?Is that because of the array or linq?

Using string to search

var keyWord="Lyly,Tom,Jack,Rose"; //and so on,more than 500
names
var student= Context.Students.Where(i =>
stations.Contains(i.Name));//very slow

Using array to search

var keyWord="Lyly,Tom,Jack,Rose"; //and so on,more than 500
names
 var keyWordArray=keyWord.split(',');
var student= Context.Students.Where(i =>
keyWordArray.Contains(i.Name));//fast

Redirecting a GET request to another app's POST request in a rails controller
Web Development

I have a controller action that is triggered by a GET route, which under some conditions, I want to redirect to the POST route of another app on another server.


I'm aware of redirect_to "http://somewhere.com/thing_to_post_to" but there doesn't seem to be a way of specifying the http method. This intended for AJAX requests not pages, so it isn't acceptable to return a javascript to direct the browser.


Is this possible?




HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .