WeatherForecastController.cs 977 B

1234567891011121314151617181920212223242526272829303132
  1. using Microsoft.AspNetCore.Mvc;
  2. namespace AirPlayer.Controllers;
  3. [ApiController]
  4. [Route("api/[controller]/[action]")]
  5. public class WeatherForecastController : ControllerBase
  6. {
  7. private static readonly string[] Summaries = new[]
  8. {
  9. "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
  10. };
  11. private readonly ILogger<WeatherForecastController> _logger;
  12. public WeatherForecastController(ILogger<WeatherForecastController> logger)
  13. {
  14. _logger = logger;
  15. }
  16. [HttpGet(Name = "GetWeatherForecast")]
  17. public IEnumerable<WeatherForecast> Get()
  18. {
  19. return Enumerable.Range(1, 5).Select(index => new WeatherForecast
  20. {
  21. Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
  22. TemperatureC = Random.Shared.Next(-20, 55),
  23. Summary = Summaries[Random.Shared.Next(Summaries.Length)]
  24. })
  25. .ToArray();
  26. }
  27. }