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.Models; using WebApplication3.Clases; namespace WebApplication3.Controllers { //[Route("api/[controller]")] //[ApiController] [ApiExplorerSettings(IgnoreApi = true)] public class TsPozoController : ControllerBase { private readonly AquiferContext _context; public TsPozoController(AquiferContext context) { _context = context; } // GET: api/TsPozo [HttpGet] public async Task>> GetTsPozos() { return await _context.TsPozos.ToListAsync(); } // GET: api/TsPozo/5 [HttpGet("{id}")] //public async Task> GetTsPozo(uint id) public TimeSerie[] GetTsPozo(uint id) { //var tsPozo = await _context.TsPozos.FindAsync(id); var tsPozos = _context.TsPozos.Where(x => x.IdPozo == id); List timeSeries = new List(); TimeSerie _timeSerie = null; if (tsPozos == null) { return null; } foreach(TsPozo tsp in tsPozos) { _timeSerie = new TimeSerie(); _timeSerie.Hora = tsp.MarcaTiempo; _timeSerie.Valor = tsp.Valor; timeSeries.Add(_timeSerie); } return timeSeries.ToArray(); } // PUT: api/TsPozo/5 // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id}")] public async Task PutTsPozo(uint id, TsPozo tsPozo) { if (id != tsPozo.Id) { return BadRequest(); } _context.Entry(tsPozo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TsPozoExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } // POST: api/TsPozo // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPost] public async Task> PostTsPozo(TsPozo tsPozo) { _context.TsPozos.Add(tsPozo); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (TsPozoExists(tsPozo.Id)) { return Conflict(); } else { throw; } } return CreatedAtAction("GetTsPozo", new { id = tsPozo.Id }, tsPozo); } // DELETE: api/TsPozo/5 [HttpDelete("{id}")] public async Task DeleteTsPozo(int id) { var tsPozo = await _context.TsPozos.FindAsync(id); if (tsPozo == null) { return NotFound(); } _context.TsPozos.Remove(tsPozo); await _context.SaveChangesAsync(); return NoContent(); } private bool TsPozoExists(uint id) { return _context.TsPozos.Any(e => e.Id == id); } [NonAction] public async Task DeleteTsPozoFromPozo(uint id) { List tsPozos = _context.TsPozos.Where(x => x.IdPozo == id).ToList(); if (tsPozos == null) { return NotFound(); } tsPozos.ForEach( x => _context.TsPozos.Remove(x) ); await _context.SaveChangesAsync(); return NoContent(); } } }