123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 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 TsPiezometerController: ControllerBase
- {
- private readonly AquiferContext _context;
-
- public TsPiezometerController(AquiferContext context)
- {
- _context = context;
- }
-
- // GET: api/TsPiezometer
- [HttpGet]
- public async Task<ActionResult<IEnumerable<TsPiezometer>>> GetTsPiezometers()
- {
- return await _context.TsPiezometers.ToListAsync();
- }
-
- // GET: api/TsPiezometer/5
- [HttpGet("{id}")]
- //public async Task<ActionResult<TsPozo>> GetTsPozo(uint id)
- public TimeSerie[] GetTsPiezometer(uint id)
- {
-
- //var tsPozo = await _context.TsPozos.FindAsync(id);
- var tsPiezometers = _context.TsPiezometers.Where(x => x.PiezometerId == id);
-
- List<TimeSerie> timeSeries = new ();
- TimeSerie timeSerie = null;
-
- if (tsPiezometers == null)
- {
- return null;
- }
-
- foreach(TsPiezometer tsp in tsPiezometers)
- {
- timeSerie = new ();
- timeSerie.Hora = tsp.Day;
- timeSerie.Valor = tsp.Quote;
- timeSeries.Add(timeSerie);
- }
-
- return timeSeries.ToArray();
- }
-
- // PUT: api/TsPiezometer/5
- // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
- [HttpPut("{id}")]
- public async Task<IActionResult> PutTsPiezometer(uint id, TsPozo tsPozo)
- {
- if (id != tsPozo.Id)
- {
- return BadRequest();
- }
-
- _context.Entry(tsPozo).State = EntityState.Modified;
-
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!TsPiezometerExists(id))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
-
- return NoContent();
- }
-
- // POST: api/TsPiezometer
- // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
- [HttpPost]
- public async Task<ActionResult<TsPozo>> PostTsPiezometer(TsPiezometer tsPiezometer)
- {
- _context.TsPiezometers.Add(tsPiezometer);
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateException)
- {
- if (TsPiezometerExists(tsPiezometer.Id))
- {
- return Conflict();
- }
- else
- {
- throw;
- }
- }
-
- return CreatedAtAction("GetTsPozo", new { id = tsPiezometer.Id }, tsPiezometer);
- }
-
- // 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 TsPiezometerExists(uint id)
- {
- return _context.TsPozos.Any(e => e.Id == id);
- }
- }
- }
|