WeatherForecastController.cs 1.1 KB

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