TsRecargaController.cs 3.4KB

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