123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- 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 PiezometriaController : ControllerBase
- {
- private readonly AquiferContext _context;
- private TsPozoController _tsPozoController;
-
-
- public PiezometriaController(AquiferContext context)
- {
- _context = context;
- _tsPozoController = new TsPozoController(context);
-
- }
-
- // GET: api/Pozo
- [HttpGet]
- public async Task<ActionResult<IEnumerable<Piezometria>>> GetPozos()
- {
- return await _context.Piezometria.ToListAsync();
- }
-
- // GET: api/Pozo/5
- [HttpGet("{id}")]
- [ProducesResponseType(200)]
- [ProducesResponseType(404)]
- public async Task<ActionResult<Piezometria>> GetPozo(uint id)
- {
- var piezometria = await _context.Piezometria.FindAsync(id);
-
- if (piezometria == null)
- {
- return NotFound();
- }
-
- return piezometria;
- }
-
- // PUT: api/Pozo/5
- // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
- //[HttpPut("{id}")]
- //public async Task<IActionResult> PutPozo(uint id, [FromBody] DatosPozoRecarga datos)
- //{
- // Pozo pozo = _context.Pozos.Find(id);
-
- // if (id != pozo.Id)
- // {
- // return BadRequest();
- // }
-
- // pozo.IdAquifero = (datos.Acuifero != null && pozo.IdAquifero != datos.Acuifero) ? datos.Acuifero : pozo.IdAquifero;
- // pozo.IdSimulacion = (datos.Simulacion != null && pozo.IdSimulacion != datos.Simulacion) ? datos.Simulacion : pozo.IdSimulacion;
- // pozo.Latitud = (datos.Latitud != null && pozo.Latitud != datos.Latitud) ? datos.Latitud : pozo.Latitud;
- // pozo.Longitud = (datos.Longitud != null && pozo.Longitud != datos.Longitud) ? datos.Longitud : pozo.Longitud;
- // pozo.Maximo = (datos.Maximo != null && pozo.Maximo != datos.Maximo) ? datos.Maximo : pozo.Maximo;
- // pozo.Nombre = (datos.Nombre != null && pozo.Nombre != datos.Nombre) ? datos.Nombre : pozo.Nombre;
-
- // _context.Entry(pozo).State = EntityState.Modified;
-
- // try
- // {
- // await _context.SaveChangesAsync();
- // }
- // catch (DbUpdateConcurrencyException)
- // {
- // if (!PiezometriaExists(id))
- // {
- // return NotFound();
- // }
- // else
- // {
- // throw;
- // }
- // }
-
- // return CreatedAtAction("GetPozo", new { id = pozo.Id }, pozo);
- //}
-
- // POST: api/Pozo
- // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
- [HttpPost]
- [ProducesResponseType(200)]
- [ProducesResponseType(409)]
- public async Task<ActionResult<Piezometria>> PostPiezometria(Piezometria piezometria)
- {
- Logger.WriteLog("Se procede a guardar piezometria");
- _context.Piezometria.Add(piezometria);
- try
- {
- Logger.WriteLog("Guardar cambios async");
- await _context.SaveChangesAsync();
-
- }
- catch (DbUpdateException ex)
- {
- if (PiezometriaExists(piezometria.Id))
- {
- return Conflict();
- }
- else
- {
- Logger.WriteLog("FALLO AL GUARDAR PIEZOMETRIA");
- Logger.WriteLog(ex.Message);
- Logger.WriteLog(ex.InnerException.Message);
- throw;
- }
- }
-
- return Ok(piezometria);
- //return CreatedAtAction("GetPiezometria", new { id = piezometria.Id }, piezometria);
- }
-
- // DELETE: api/Pozo/5
- [HttpDelete("{id}")]
- [ProducesResponseType(404)]
- [ProducesResponseType(204)]
- public async Task<IActionResult> DeletePiezometria(uint id)
- {
- var piezometria = await _context.Piezometria.FindAsync(id);
- if (piezometria == null)
- {
- return NotFound();
- }
-
- _context.Piezometria.Remove(piezometria);
- await _context.SaveChangesAsync();
-
- return NoContent();
- }
-
- private bool PiezometriaExists(uint id)
- {
- return _context.Piezometria.Any(e => e.Id == id);
- }
-
- [NonAction]
- public void GetDimensions(uint idSimulacion, out int rows, out int cols)
- {
- Piezometria piezometria = _context.Piezometria.Where(x => x.IdSimulacion == idSimulacion).FirstOrDefault();
- rows = piezometria.Rows;
- cols = piezometria.Columns;
- }
-
- }
- }
|