Skip to content

Instantly share code, notes, and snippets.

@domingoladron
Last active May 22, 2020 23:28
Show Gist options
  • Save domingoladron/d115041d3c1d1fe03c722936ffe1d51e to your computer and use it in GitHub Desktop.
Save domingoladron/d115041d3c1d1fe03c722936ffe1d51e to your computer and use it in GitHub Desktop.
aspnetcore.webapiconventions.oldway.cs
[HttpGet]
public async Task<ActionResult<IEnumerable<WeatherForecast>>> GetAsync()
{
var rng = new Random();
var notFound = false;
var response = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
});
//return a NotFound Result if, well, not found (404)
if(notFound)
{
return new NotFoundResult();
}
//otherwise return our weather forecasts (200)
return await Task.Run(() => new OkObjectResult(response));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment