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<CORREOSAREAMS> lista = this._context.CORREOSAREAMS.ToList();
|
|
|
|
return Ok(lista);
|
|
} catch (Exception ex)
|
|
{
|
|
return BadRequest(ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult post([FromBody] CORREOSAREAMS 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] CORREOSAREAMS actualizar)
|
|
{
|
|
|
|
try
|
|
{
|
|
CORREOSAREAMS? existente = this._context.CORREOSAREAMS.FirstOrDefault(c => c.NU_PK_CRRMS == actualizar.NU_PK_CRRMS);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|