WeatherForecastController.cs 1.3 KB

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