WeatherForecastController.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Logging;
  7. namespace WebServiceApi.Test.Controllers
  8. {
  9. [ApiController]
  10. [Route("api")]
  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("Q")]
  23. public IActionResult Q()
  24. {
  25. var r = Demo.Instance.Query();
  26. return new JsonResult(r);
  27. }
  28. [HttpGet("C")]
  29. public IActionResult C()
  30. {
  31. var r = Demo.Instance.Complete();
  32. return new JsonResult(r);
  33. }
  34. [HttpGet]
  35. public IEnumerable<WeatherForecast> Get()
  36. {
  37. var rng = new Random();
  38. return Enumerable.Range(1, 5).Select(index => new WeatherForecast
  39. {
  40. Date = DateTime.Now.AddDays(index),
  41. TemperatureC = rng.Next(-20, 55),
  42. Summary = Summaries[rng.Next(Summaries.Length)]
  43. })
  44. .ToArray();
  45. }
  46. }
  47. }