WeatherForecastController.cs 1.2 KB

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