82 lines
3.0 KiB
C#
82 lines
3.0 KiB
C#
using bdAntifraude.db;
|
|
using bdAntifraude.dbcontext;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Serialize.Linq.Serializers;
|
|
using System.Linq.Expressions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace SwaggerAntifraude.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class CODIGOSPOSTALESController : GenericoController<CODIGOSPOSTALES, int>
|
|
{
|
|
public CODIGOSPOSTALESController()
|
|
: base()
|
|
{
|
|
Debug.WriteLine("aqui");
|
|
}
|
|
|
|
//[Authorize(Policy = "LecturaPolicy")]
|
|
//[HttpGet("ObtenerPorCodigo/{codigopostal}")]
|
|
//public async Task<IActionResult> ObtenerPorCodigo(int codigopostal)
|
|
//{
|
|
// try
|
|
// {
|
|
// string cod = codigopostal.ToString();
|
|
// using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
|
// {
|
|
// var enumes = context.CODIGOSPOSTALES.Include(y => y.CODIGOMUNICIPIONavigation).Where(p => p.CODIGOPOSTAL == cod)
|
|
// .AsNoTracking().ToList();
|
|
|
|
// if (enumes == null)
|
|
// return NotFound();
|
|
|
|
// return Ok(enumes);
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
|
// }
|
|
//}
|
|
|
|
[Authorize(Policy = "LecturaPolicy")]
|
|
[HttpPost("MunicipiosExtend")]
|
|
public async Task<IActionResult> MunicipiosExtendo([FromBody]ExpressionWrapper request)
|
|
{
|
|
try
|
|
{
|
|
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
|
{
|
|
// Crear el deserializador
|
|
var serializer = new ExpressionSerializer(new Serialize.Linq.Serializers.JsonSerializer());
|
|
|
|
// Deserializar la expresión
|
|
var deserializedExpression = serializer.DeserializeText(request.Expression) as Expression<Func<CODIGOSPOSTALES, bool>>;
|
|
if (deserializedExpression == null)
|
|
{
|
|
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
|
}
|
|
|
|
var motAdmin = await context.CODIGOSPOSTALES
|
|
.Where(deserializedExpression)
|
|
.Include(y => y.CODIGOMUNICIPIONavigation)
|
|
.ThenInclude(cp => cp.CODIGOPROVINCIANavigation)
|
|
.AsNoTracking().ToListAsync();
|
|
if (motAdmin == null)
|
|
return NotFound();
|
|
|
|
return Ok(motAdmin);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|