77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
![]() |
using MSAdminUsuarios.Context;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace MSAdminUsuarios.Controllers
|
|||
|
{
|
|||
|
[ApiController]
|
|||
|
[Route("[controller]")]
|
|||
|
public class PerfilesController : ControllerBase
|
|||
|
{
|
|||
|
private readonly ModelContext _context;
|
|||
|
|
|||
|
public PerfilesController(ModelContext context)
|
|||
|
{
|
|||
|
_context = context;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public async Task<IActionResult> GetPerfiles()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var consulta = from dm in _context.PERFILESMs
|
|||
|
where dm.BL_ESTADO_PFL>=0
|
|||
|
select dm;
|
|||
|
|
|||
|
return Ok(consulta);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public async Task<IActionResult> GuardarPerfiles(PERFIL guardado)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
if (guardado == null) return ValidationProblem();
|
|||
|
|
|||
|
_context.PERFILESMs.Add(guardado);
|
|||
|
await _context.SaveChangesAsync();
|
|||
|
return Ok();
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPatch]
|
|||
|
public async Task<IActionResult> EditarPerfiles(PERFIL editado)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (editado == null) return ValidationProblem();
|
|||
|
|
|||
|
var existe = _context.PERFILESMs.Find(editado.NU_PK_PFL);
|
|||
|
|
|||
|
existe.TX_PERFIL_PFL = editado.TX_PERFIL_PFL;
|
|||
|
existe.BL_ESTADO_PFL = editado.BL_ESTADO_PFL;
|
|||
|
|
|||
|
_context.PERFILESMs.Update(existe);
|
|||
|
await _context.SaveChangesAsync();
|
|||
|
return Ok();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
return BadRequest(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|