WeatherForecastController.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Azure.Cosmos;
  7. using Microsoft.Extensions.Logging;
  8. using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;
  9. namespace CosmosDBTest.Controllers
  10. {
  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. private readonly IAzureCosmosDBRepository azureCosmosDBRepository;
  21. public WeatherForecastController(ILogger<WeatherForecastController> logger, IAzureCosmosDBRepository _azureCosmosDBRepository)
  22. {
  23. _logger = logger;
  24. azureCosmosDBRepository = _azureCosmosDBRepository;
  25. }
  26. [HttpGet]
  27. public IEnumerable<WeatherForecast> Get()
  28. {
  29. var rng = new Random();
  30. return Enumerable.Range(1, 5).Select(index => new WeatherForecast
  31. {
  32. Date = DateTime.Now.AddDays(index),
  33. TemperatureC = rng.Next(-20, 55),
  34. Summary = Summaries[rng.Next(Summaries.Length)]
  35. })
  36. .ToArray();
  37. }
  38. [HttpGet("GetData")]
  39. public async Task<IEnumerable<Volume>> GetData()
  40. {
  41. return await azureCosmosDBRepository.FindSQL<Volume>("select * from c where c.id= '1'" ,true);
  42. }
  43. }
  44. }