123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- 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<ActionResult<IEnumerable<TsPozo>>> GetTsPozos()
- {
- return await _context.TsPozos.ToListAsync();
- }
-
- // GET: api/TsPozo/5
- [HttpGet("{id}")]
- //public async Task<ActionResult<TsPozo>> 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<TimeSerie> timeSeries = new List<TimeSerie>();
- 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<IActionResult> 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<ActionResult<TsPozo>> 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<IActionResult> 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<IActionResult> DeleteTsPozoFromPozo(uint id)
- {
- List<TsPozo> tsPozos = _context.TsPozos.Where(x => x.IdPozo == id).ToList<TsPozo>();
-
- if (tsPozos == null)
- {
- return NotFound();
- }
-
- tsPozos.ForEach( x =>
- _context.TsPozos.Remove(x)
- );
-
- await _context.SaveChangesAsync();
-
- return NoContent();
- }
- }
- }
|