Forum Discussion

bec1442's avatar
bec1442
New Contributor
10 days ago

return multiple listings based on the criteria

I have an Action [HttpGet]  that returns all entries from a class Services and Status , schema similar to this

"hstryTimeStamp": "string",

    "hstryDateTime": "2024-04-25T23:17:44.955Z",

    "ServiceName": "string",

    "mobilePhone": "string",

    "ethnicity": "string",

    "Status": [

      {

        "statusSer": 0,

        "ServiceSer": 0,

        "statusId": "string",

        "startDateTime": "2024-04-25T23:17:44.955Z",

        "Status": "string",   

       

 

I would like to search by Status  (e.g. Running” /”Stopped”) and also display ServiceNmae for all records

How do I get all listing where Status is “Running” and the “ServiceName”?

 

I’ve tried this but this returns one entry

//action Get By Status

[HttpGet("{Status}")]

[ProducesResponseType(typeof(Statu), StatusCodes.Status204NoContent)]

[ProducesResponseType(typeof(Statu), StatusCodes.Status400BadRequest)]

public async Task<IActionResult> GetByStatus(string Status)

{

    var _status = Convert.ToString(Status);

    var status = await _context.Courses.FirstOrDefaultAsync(i => i.Status == _status );

    return status == null ? NotFound() : Ok(status);

}

No RepliesBe the first to reply