Last active
May 22, 2020 23:28
-
-
Save domingoladron/d115041d3c1d1fe03c722936ffe1d51e to your computer and use it in GitHub Desktop.
aspnetcore.webapiconventions.oldway.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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