123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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<ActionResult<IEnumerable<TsRecarga>>> 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<TimeSerie> timeSeries = new List<TimeSerie>();
- 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<IActionResult> 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<ActionResult<TsRecarga>> 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<IActionResult> 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);
- }
- }
- }
|