WeatherForecastController.cs 1.0 KB

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