using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using WebApplication3.Clases; using WebApplication3.Models; namespace WebApplication3.Controllers { //[Route("api/[controller]")] //[ApiController] [ApiExplorerSettings(IgnoreApi = true)] public class TsRecargaController : ControllerBase { private readonly AquiferContext _context; public TsRecargaController(AquiferContext context) { _context = context; } // GET: api/TsRecarga [HttpGet] public async Task>> GetTsRecargas() { return await _context.TsRecargas.ToListAsync(); } // GET: api/TsRecarga/5 [HttpGet("{id}")] public TimeSerie[] GetTsRecarga(uint id) { //var tsPozo = await _context.TsPozos.FindAsync(id); var tsRecargas = _context.TsRecargas.Where(x => x.IdRecarga == id); List timeSeries = new List(); TimeSerie _timeSerie = null; if (tsRecargas == null) { return null; } foreach (TsRecarga tsr in tsRecargas) { _timeSerie = new TimeSerie(); _timeSerie.Hora = tsr.MarcaTiempo; _timeSerie.Valor = tsr.Valor; timeSeries.Add(_timeSerie); } return timeSeries.ToArray(); } // PUT: api/TsRecarga/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] public async Task PutTsRecarga(int id, TsRecarga tsRecarga) { if (id != tsRecarga.Id) { return BadRequest(); } _context.Entry(tsRecarga).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TsRecargaExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } // POST: api/TsRecarga // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] public async Task> PostTsRecarga(TsRecarga tsRecarga) { _context.TsRecargas.Add(tsRecarga); await _context.SaveChangesAsync(); return CreatedAtAction("GetTsRecarga", new { id = tsRecarga.Id }, tsRecarga); } // DELETE: api/TsRecarga/5 [HttpDelete("{id}")] public async Task DeleteTsRecarga(int id) { var tsRecarga = await _context.TsRecargas.FindAsync(id); if (tsRecarga == null) { return NotFound(); } _context.TsRecargas.Remove(tsRecarga); await _context.SaveChangesAsync(); return NoContent(); } private bool TsRecargaExists(int id) { return _context.TsRecargas.Any(e => e.Id == id); } } }