TsRecargaController.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.EntityFrameworkCore;
  8. using WebApplication3.Clases;
  9. using WebApplication3.Models;
  10. namespace WebApplication3.Controllers
  11. {
  12. //[Route("api/[controller]")]
  13. //[ApiController]
  14. [ApiExplorerSettings(IgnoreApi = true)]
  15. public class TsRecargaController : ControllerBase
  16. {
  17. private readonly AquiferContext _context;
  18. public TsRecargaController(AquiferContext context)
  19. {
  20. _context = context;
  21. }
  22. // GET: api/TsRecarga
  23. [HttpGet]
  24. public async Task<ActionResult<IEnumerable<TsRecarga>>> GetTsRecargas()
  25. {
  26. return await _context.TsRecargas.ToListAsync();
  27. }
  28. // GET: api/TsRecarga/5
  29. [HttpGet("{id}")]
  30. public TimeSerie[] GetTsRecarga(uint id)
  31. {
  32. //var tsPozo = await _context.TsPozos.FindAsync(id);
  33. var tsRecargas = _context.TsRecargas.Where(x => x.IdRecarga == id);
  34. List<TimeSerie> timeSeries = new List<TimeSerie>();
  35. TimeSerie _timeSerie = null;
  36. if (tsRecargas == null)
  37. {
  38. return null;
  39. }
  40. foreach (TsRecarga tsr in tsRecargas)
  41. {
  42. _timeSerie = new TimeSerie();
  43. _timeSerie.Hora = tsr.MarcaTiempo;
  44. _timeSerie.Valor = tsr.Valor;
  45. timeSeries.Add(_timeSerie);
  46. }
  47. return timeSeries.ToArray();
  48. }
  49. // PUT: api/TsRecarga/5
  50. // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
  51. [HttpPut("{id}")]
  52. public async Task<IActionResult> PutTsRecarga(int id, TsRecarga tsRecarga)
  53. {
  54. if (id != tsRecarga.Id)
  55. {
  56. return BadRequest();
  57. }
  58. _context.Entry(tsRecarga).State = EntityState.Modified;
  59. try
  60. {
  61. await _context.SaveChangesAsync();
  62. }
  63. catch (DbUpdateConcurrencyException)
  64. {
  65. if (!TsRecargaExists(id))
  66. {
  67. return NotFound();
  68. }
  69. else
  70. {
  71. throw;
  72. }
  73. }
  74. return NoContent();
  75. }
  76. // POST: api/TsRecarga
  77. // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
  78. [HttpPost]
  79. public async Task<ActionResult<TsRecarga>> PostTsRecarga(TsRecarga tsRecarga)
  80. {
  81. _context.TsRecargas.Add(tsRecarga);
  82. await _context.SaveChangesAsync();
  83. return CreatedAtAction("GetTsRecarga", new { id = tsRecarga.Id }, tsRecarga);
  84. }
  85. // DELETE: api/TsRecarga/5
  86. [HttpDelete("{id}")]
  87. public async Task<IActionResult> DeleteTsRecarga(int id)
  88. {
  89. var tsRecarga = await _context.TsRecargas.FindAsync(id);
  90. if (tsRecarga == null)
  91. {
  92. return NotFound();
  93. }
  94. _context.TsRecargas.Remove(tsRecarga);
  95. await _context.SaveChangesAsync();
  96. return NoContent();
  97. }
  98. private bool TsRecargaExists(int id)
  99. {
  100. return _context.TsRecargas.Any(e => e.Id == id);
  101. }
  102. }
  103. }