I'm trying to query for the "UserType" object, and get the attribute "name"
So the whole JSON object is User: and the api call should look like this:
api/user?userTypeName=randomUserTypeName
Where I can search for a specific userTypeName, and return the name.
API call:
Here I want to user the FromQuery, to be able to search for the userTypeName and check for the userTypeName to be equal to the entered Name.
// GET: /api/User/userTypeName
[HttpGet("{userTypeName}")]
public async Task<ActionResult<IEnumerable<User>>> GetAsync(([FromQuery(Name = "userTypeName")]string userTypeName) {
var result = await ctx.User
.Include(x => x.UserType)
.Where(x => x.UserType.Name.ToLower() == UserTypeName.ToLower())
.ToListAsync();
if (result == null) return BadRequest();
return result;
}
The object looks like this:
{
"id": 9,
"userTypeId": 1,
"userType": {
"id": 1,
"name": "randomUserTypeName",
"users":
[
{
"id": 11,
"userTypeId": 1,
"userUrl": "https://userurl",
"username": "eee",
"password": "eee",
}
]
}