I work on blazor server side I face issues i can't return only employeeid from web api request without request details
so i need to return data from web api reuest as array of "employeeID": "212334" etc
and no need to return details of request as ( id ,exception,status,iscancelled,iscompleted,iscompletedsuccesfully,asyncState,
isFaulted,creationOptions
only need return array of employeeid
web api return data i need to modify it as below :
[HttpGet]
[Route("GetAllEmployee/{searchText}")]
public async Task<IActionResult> GetAllEmployee(string searchText)
{
string query = "";
query = "SELECT cast(EMP.YAAN8 as varchar(20)) as EmployeeID,EMP.YAALPH AS EmployeeName FROM CRPDTA.F060116 EMP WHERE cast(EMP.YAAN8 as varchar(20)) LIKE '%" + searchText + "%' WITH UR";
try
{
ICollection<object> ApplicationsDataValues = new List<object>();
using (var command = con.CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
await command.Connection.OpenAsync();
using (var reader = await command.ExecuteReaderAsync())
{
while (await reader.ReadAsync())
{
ApplicationsDataValues.Add(new
{
EmployeeID = reader.GetFieldValueAsync<string>(0)
});
}
}
}
await con.CloseAsync();
return StatusCode(200, ApplicationsDataValues); // Get all users
}
catch (Exception e)
{
return StatusCode(500, e);
}
}
it return data as below :
[
{
"employeeID": {
"result": "212334",
"id": 251,
"exception": null,
"status": 5,
"isCanceled": false,
"isCompleted": true,
"isCompletedSuccessfully": true,
"creationOptions": 0,
"asyncState": null,
"isFaulted": false
}
},
{
"employeeID": {
"result": "212331",
"id": 252,
"exception": null,
"status": 5,
"isCanceled": false,
"isCompleted": true,
"isCompletedSuccessfully": true,
"creationOptions": 0,
"asyncState": null,
"isFaulted": false
}
},
{
"employeeID": {
"result": "271233",
"id": 253,
"exception": null,
"status": 5,
"isCanceled": false,
"isCompleted": true,
"isCompletedSuccessfully": true,
"creationOptions": 0,
"asyncState": null,
"isFaulted": false
}
}
expected result returned
[
{
"employeeID": "212334"
},
{
"employeeID": "212331"
},
{
"employeeID": "271233"
}
]