Created
May 22, 2020 23:48
-
-
Save domingoladron/cc5aa4780484dd2666532a3a6b83241b to your computer and use it in GitHub Desktop.
aspnetcore.webapiconventions.newway.cs
This file contains 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] | |
[ApiConventionMethod(typeof(DefaultApiConventions), | |
nameof(DefaultApiConventions.Get))] | |
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(notFound) | |
{ | |
return new NotFoundResult(); | |
} | |
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