70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
![]() |
using Microsoft.AspNetCore.Http;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using MSAdminUsuarios.Context;
|
|||
|
using Security;
|
|||
|
|
|||
|
namespace MSAdminUsuarios.Controllers
|
|||
|
{
|
|||
|
[Route("[controller]")]
|
|||
|
[ApiController]
|
|||
|
public class CorreosAreaController : ControllerBase
|
|||
|
{
|
|||
|
private readonly ModelContext _context;
|
|||
|
public CorreosAreaController(ModelContext context)
|
|||
|
{
|
|||
|
_context = context;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public IActionResult obtener()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
List<CorreosArea> lista = this._context.CORREOSAREAMS.ToList();
|
|||
|
|
|||
|
return Ok(lista);
|
|||
|
} catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public IActionResult post([FromBody] CorreosArea nuevo)
|
|||
|
{
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
this._context.CORREOSAREAMS.Add(nuevo);
|
|||
|
this._context.SaveChanges();
|
|||
|
|
|||
|
return Ok("Registro guardado correctamente.");
|
|||
|
|
|||
|
} catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPatch]
|
|||
|
public IActionResult patch([FromBody] CorreosArea actualizar)
|
|||
|
{
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
CorreosArea? existente = this._context.CORREOSAREAMS.FirstOrDefault(c => c.NU_PK_CORA == actualizar.NU_PK_CORA);
|
|||
|
if (existente == null) return BadRequest("Registro inexistente");
|
|||
|
|
|||
|
this._context.Entry(existente).CurrentValues.SetValues(actualizar);
|
|||
|
this._context.SaveChanges();
|
|||
|
|
|||
|
return Ok("Registro guardado correctamente.");
|
|||
|
|
|||
|
} catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|