Primer push
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.Controllers;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ACTOSADMINPREPController : GenericoController<ACTOSADMINPREP, int>
|
||||
{
|
||||
public ACTOSADMINPREPController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("MotivosExtend/{idActo}")]
|
||||
public async Task<IActionResult> TiposExtend(int idActo)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var motAdmin = context.ACTOSADMINPREP.Include(v => v.IDMOTIVOADMINISTRATIVONavigation).Include(v => v.IDMOTIVOADMINISTRATIVONavigation.IDTIPOAPTOSNavigation).FirstOrDefault(p => p.IDACTOADMINISTRATIVO == idActo);
|
||||
if (motAdmin == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(motAdmin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public override async Task<IActionResult> Filtrar([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<ACTOSADMINPREP, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.ACTOSADMINPREP.Where(deserializedExpression)
|
||||
.Include(m => m.IDMOTIVOADMINISTRATIVONavigation)
|
||||
.ThenInclude(aa => aa.IDTIPOAPTOSNavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ADSCRIPCIONController : GenericoController<ADSCRIPCION, int>
|
||||
{
|
||||
public ADSCRIPCIONController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using bdAntifraude.clases;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SwaggerAntifraude.Models;
|
||||
using SwaggerAntifraude.Servicios;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AlmacenamientoController : ControllerBase
|
||||
{
|
||||
private readonly ServicioAlmacenamiento _servicio = new ServicioAlmacenamiento();
|
||||
|
||||
[Authorize(Policy = "SupervisorPolicy")]
|
||||
[HttpPost("almacenar-fichero")]
|
||||
public IActionResult AlmacenarFichero([FromBody] AlmacenaFicheroAtransmitir solicitud)
|
||||
{
|
||||
if (solicitud == null || string.IsNullOrEmpty(solicitud.Fichero))
|
||||
return BadRequest("Solicitud inválida.");
|
||||
|
||||
var resultado = _servicio.DevolverResultadoAlmacenaFicheroAtransmitir(
|
||||
solicitud.IdRegistro,
|
||||
solicitud.Tabla,
|
||||
solicitud.Fichero
|
||||
);
|
||||
|
||||
if (resultado.Resultado == 0)
|
||||
return Ok(resultado);
|
||||
|
||||
return StatusCode(500, resultado);
|
||||
}
|
||||
|
||||
[Authorize(Policy = "SupervisorPolicy")]
|
||||
[HttpPost("obtener-fichero")]
|
||||
public IActionResult ObtenerFichero(PeticionFichero solicitud)
|
||||
{
|
||||
if (string.IsNullOrEmpty(solicitud.Tabla) || solicitud.IdRegistro <= 0)
|
||||
return BadRequest("Solicitud inválida. Asegúrese de enviar los parámetros requeridos.");
|
||||
|
||||
var resultado = _servicio.DevolverObtenFicheroAtransmitir(solicitud.IdRegistro, solicitud.Tabla, solicitud.Nif);
|
||||
|
||||
if (resultado.Resultado == 0)
|
||||
{
|
||||
// Devolver el archivo como un PDF descargable
|
||||
return Ok(resultado);
|
||||
}
|
||||
|
||||
return StatusCode(500, resultado);
|
||||
}
|
||||
}
|
||||
}
|
||||
221
Antifraude.Net/SwaggerAntifraude/Controllers/AuthController.cs
Normal file
221
Antifraude.Net/SwaggerAntifraude/Controllers/AuthController.cs
Normal file
@@ -0,0 +1,221 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using SwaggerAntifraude.DTOs;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public AuthController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("login")]
|
||||
public IActionResult Login([FromBody] LoginDto loginDto)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
var (token, persona) = AuthenticateUser(loginDto);
|
||||
|
||||
if (token == null)
|
||||
return Unauthorized("Nombre de usuario o contraseña incorrectos.");
|
||||
|
||||
if (token.Equals("no autorizado"))
|
||||
{
|
||||
return Unauthorized("Usuario no autorizado");
|
||||
}
|
||||
return Ok(new
|
||||
{
|
||||
Token = token,
|
||||
User = new
|
||||
{
|
||||
persona.NIF,
|
||||
persona.NOMBRE,
|
||||
persona.APELLIDOS,
|
||||
persona.ADMINISTRARPTYREGISTRO
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("login-cert")]
|
||||
public IActionResult LoginWithCertificateGet([FromQuery] bool iframe = false)
|
||||
{
|
||||
// Obtener el certificado enviado durante el handshake TLS
|
||||
var clientCert = HttpContext.Connection.ClientCertificate;
|
||||
if (clientCert == null)
|
||||
return Unauthorized("Certificado no proporcionado.");
|
||||
|
||||
// Extraer el DNI desde el certificado
|
||||
var dni = ObtenerDNI(clientCert);
|
||||
if (string.IsNullOrEmpty(dni))
|
||||
return Unauthorized("No se pudo obtener un DNI válido del certificado.");
|
||||
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
{
|
||||
// Mapeo de ejemplo (como en tu código)
|
||||
if (dni == "25621303Q" || dni == "52234173T" ||dni == "47201739N")
|
||||
dni = "44286377S";
|
||||
|
||||
var persona = context.PERSONAS.FirstOrDefault(p => p.NIF == dni);
|
||||
if (persona == null)
|
||||
return Unauthorized("Usuario no encontrado en la base de datos.");
|
||||
|
||||
// Generar token JWT
|
||||
var jwtSettings = _configuration.GetSection("Jwt");
|
||||
var key = Encoding.UTF8.GetBytes(jwtSettings["Key"]);
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtRegisteredClaimNames.Sub, persona.NIF),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
|
||||
new Claim(ClaimTypes.Role, persona.ADMINISTRARPTYREGISTRO == true ? "Supervisor" : "Lectura")
|
||||
};
|
||||
|
||||
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Expires = DateTime.UtcNow.AddMinutes(double.Parse(jwtSettings["ExpiresInMinutes"])),
|
||||
Issuer = jwtSettings["Issuer"],
|
||||
Audience = jwtSettings["Audience"],
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
var jwtToken = tokenHandler.WriteToken(token);
|
||||
|
||||
if (iframe)
|
||||
{
|
||||
// Generar una página HTML mínima que envíe el token y datos del usuario mediante postMessage al contexto padre
|
||||
var html = $@"
|
||||
<html>
|
||||
<head><title>Autenticación Certificado</title></head>
|
||||
<body>
|
||||
<script>
|
||||
window.parent.postMessage({{
|
||||
token: '{jwtToken}',
|
||||
user: {{
|
||||
NIF: '{persona.NIF}',
|
||||
NOMBRE: '{persona.NOMBRE}',
|
||||
APELLIDOS: '{persona.APELLIDOS}',
|
||||
ADMINISTRARPTYREGISTRO: {persona.ADMINISTRARPTYREGISTRO.ToString().ToLower()}
|
||||
}}
|
||||
}}, '*');
|
||||
</script>
|
||||
</body>
|
||||
</html>";
|
||||
return Content(html, "text/html; charset=utf-8");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(new
|
||||
{
|
||||
Token = jwtToken,
|
||||
User = new
|
||||
{
|
||||
persona.NIF,
|
||||
persona.NOMBRE,
|
||||
persona.APELLIDOS,
|
||||
persona.ADMINISTRARPTYREGISTRO
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
private string ObtenerDNI(X509Certificate2 certificado)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Extraer el Common Name (CN) del Subject
|
||||
var subject = certificado.Subject;
|
||||
var cnPrefix = "CN=";
|
||||
var startIndex = subject.IndexOf(cnPrefix, StringComparison.OrdinalIgnoreCase);
|
||||
if (startIndex == -1)
|
||||
return string.Empty;
|
||||
|
||||
startIndex += cnPrefix.Length;
|
||||
var endIndex = subject.IndexOf(',', startIndex);
|
||||
if (endIndex == -1) endIndex = subject.Length;
|
||||
|
||||
// Extraer el CN
|
||||
var commonName = subject.Substring(startIndex, endIndex - startIndex).Trim();
|
||||
|
||||
// Extraer el DNI del CN usando una expresión regular
|
||||
var dniMatch = System.Text.RegularExpressions.Regex.Match(commonName, @"\b\d{8}[A-Z]\b");
|
||||
if (dniMatch.Success)
|
||||
{
|
||||
return dniMatch.Value; // Devuelve solo el DNI
|
||||
}
|
||||
|
||||
return string.Empty; // No se encontró un DNI válido
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private (string token, PERSONAS persona) AuthenticateUser(LoginDto loginDto)
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
{
|
||||
var persona = context.PERSONAS.FirstOrDefault(p => p.NIF == loginDto.NombreUsuario);
|
||||
|
||||
if (persona == null || loginDto.Contraseña != "OficinaAntifraude.Tecnosis")
|
||||
{
|
||||
return (null, null);
|
||||
}
|
||||
|
||||
var jwtSettings = _configuration.GetSection("Jwt");
|
||||
var key = Encoding.UTF8.GetBytes(jwtSettings["Key"]);
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtRegisteredClaimNames.Sub, persona.NIF),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
|
||||
new Claim(ClaimTypes.Role, persona.ADMINISTRARPTYREGISTRO == true ? "Supervisor" : "Lectura")
|
||||
};
|
||||
if (loginDto.Origen.Equals("Registro") && persona.ADMINISTRARPTYREGISTRO == false)
|
||||
{
|
||||
return("no autorizado", null);
|
||||
}
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Expires = DateTime.UtcNow.AddMinutes(double.Parse(jwtSettings["ExpiresInMinutes"])),
|
||||
Issuer = jwtSettings["Issuer"],
|
||||
Audience = jwtSettings["Audience"],
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
var jwtToken = tokenHandler.WriteToken(token);
|
||||
|
||||
return (jwtToken, persona);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class COMPLEMENTONIVELController : GenericoController<COMPLEMENTONIVEL, int>
|
||||
{
|
||||
public COMPLEMENTONIVELController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar2")]
|
||||
public override async Task<IActionResult> Filtrar([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<COMPLEMENTONIVEL, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.COMPLEMENTONIVEL.Where(deserializedExpression)
|
||||
.Include(v => v.IDNIVELNavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class COMPLEMENTOSCARRERAController : GenericoController<COMPLEMENTOSCARRERA, int>
|
||||
{
|
||||
public COMPLEMENTOSCARRERAController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GruposEnumExtend/{idPersona}")]
|
||||
public async Task<IActionResult> GruposEnumExtend(int idPersona)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var motAdmin = context.COMPLEMENTOSCARRERA
|
||||
.Include(v => v.IDGRUPONavigation)
|
||||
.Include(v => v.IDTRAMONavigation)
|
||||
.Where(p => p.IDPERSONA == idPersona)
|
||||
.AsNoTracking().ToList();
|
||||
if (motAdmin == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(motAdmin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CONSOLIDACION_GRADOController : GenericoController<CONSOLIDACION_GRADO, int>
|
||||
{
|
||||
public CONSOLIDACION_GRADOController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetWithIncludes/{id}")]
|
||||
public async Task<IActionResult> GetWithIncludes(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.CONSOLIDACION_GRADO
|
||||
.Include(p => p.IDNIVELNavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDPERSONAL == id).ToListAsync(); // Filtra por IDPUESTO
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CONTRATOSController : GenericoController<CONTRATOS, int>
|
||||
{
|
||||
public CONTRATOSController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CUENTASCOTIZACIONPATRONALController : GenericoController<CUENTASCOTIZACIONPATRONAL, int>
|
||||
{
|
||||
public CUENTASCOTIZACIONPATRONALController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CUERPOController : GenericoController<CUERPO, int>
|
||||
{
|
||||
public CUERPOController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GrupoExtend")]
|
||||
public async Task<IActionResult> GrupoExtend()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var motAdmin = await context.CUERPO.Include(v => v.IDGRUPONavigation).AsNoTracking().ToListAsync();
|
||||
if (motAdmin == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(motAdmin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DOCENCIAController : GenericoController<DOCENCIA, int>
|
||||
{
|
||||
public DOCENCIAController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<PUESTOS>();
|
||||
var entity = context.DOCENCIA
|
||||
.Include(x => x.IDPERSONANavigation)
|
||||
.Include(x => x.IDTIPODOCENCIANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDDOCENCIA == id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("docenciaspersona/{idPersona}")]
|
||||
public async Task<IActionResult> DocenciaPersona(int idPersona)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.DOCENCIA
|
||||
.Include(p => p.IDPERSONANavigation)
|
||||
.Include(p => p.IDTIPODOCENCIANavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDPERSONA == idPersona).ToListAsync();
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {idPersona} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public override async Task<IActionResult> Filtrar([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<DOCENCIA, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.DOCENCIA.Where(deserializedExpression)
|
||||
.Include(x => x.IDPERSONANavigation)
|
||||
.Include(x => x.IDTIPODOCENCIANavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DOTACIONController : GenericoController<DOTACION, int>
|
||||
{
|
||||
public DOTACIONController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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 ENUMERACIONESController : GenericoController<ENUMERACIONES, int>
|
||||
{
|
||||
public ENUMERACIONESController()
|
||||
: base()
|
||||
{
|
||||
Debug.WriteLine("aqui");
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("EnumeracionesGrupo/{codigoGrupo}")]
|
||||
public async Task<IActionResult> TiposExtend(string codigoGrupo)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var enumes = context.ENUMERACIONES.Include(v => v.IDGRUPOENUMERACIONNavigation)
|
||||
.Where(p => p.IDGRUPOENUMERACIONNavigation.GRUPO == codigoGrupo)
|
||||
.AsNoTracking().ToList();
|
||||
|
||||
if (enumes == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(enumes);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class FAMILIAController : GenericoController<FAMILIA, int>
|
||||
{
|
||||
public FAMILIAController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("ParentescoExtend")]
|
||||
public async Task<IActionResult> ParentescoExtend( 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<FAMILIA, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
|
||||
var motAdmin = await context.FAMILIA
|
||||
.Where(deserializedExpression)
|
||||
.Include(v => v.IDPARENTESCONavigation)
|
||||
.AsNoTracking().ToListAsync();
|
||||
if (motAdmin == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(motAdmin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class FICHEROSController : GenericoController<FICHEROS, int>
|
||||
{
|
||||
public FICHEROSController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sobrescribe el método GetById para incluir la foto asociada al fichero.
|
||||
/// </summary>
|
||||
/// <param name="id">ID del fichero.</param>
|
||||
/// <returns>Entidad FICHEROS con todas las propiedades relacionadas cargadas.</returns>
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Incluye las propiedades relacionadas necesarias
|
||||
var fichero = context.FICHEROS
|
||||
.Include(f => f.PERSONAS) // Incluye la relación con PERSONAS
|
||||
.FirstOrDefault(f => f.IDFICHERO == id);
|
||||
|
||||
if (fichero == null)
|
||||
return NotFound("Fichero no encontrado.");
|
||||
|
||||
return Ok(fichero);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class FORMACIONController : GenericoController<FORMACION, int>
|
||||
{
|
||||
public FORMACIONController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<PUESTOS>();
|
||||
var entity = context.FORMACION
|
||||
.Include(x => x.IDPERSONANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDFORMACION == id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("formacionespersona/{idPersona}")]
|
||||
public async Task<IActionResult> FormacionPersona(int idPersona)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.FORMACION
|
||||
.Include(p => p.IDPERSONANavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDPERSONA == idPersona).ToListAsync();
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {idPersona} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using SwaggerAntifraude.Servicios;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class FormulariosController : ControllerBase
|
||||
{
|
||||
private readonly ServicioFormularios _servicioFormularios;
|
||||
|
||||
public FormulariosController(ServicioFormularios servicioFormularios)
|
||||
{
|
||||
_servicioFormularios = servicioFormularios;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Genera un formulario en PDF según la clave y parámetros proporcionados.
|
||||
/// </summary>
|
||||
/// <param name="claveFormulario">Clave del formulario (TomPos, CumTri, SolTri, etc.)</param>
|
||||
/// <param name="idPersona">ID de la persona</param>
|
||||
/// <param name="Motivo">Motivo del formulario</param>
|
||||
/// <param name="texto1">Texto adicional 1</param>
|
||||
/// <param name="texto2">Texto adicional 2 (para algunos formularios)</param>
|
||||
/// <param name="FechaEfecto">Fecha de efecto</param>
|
||||
/// <param name="Organo">Órgano competente</param>
|
||||
/// <param name="FechaEmision">Fecha de emisión del formulario</param>
|
||||
/// <param name="Extra">Campo extra opcional, según el tipo de formulario</param>
|
||||
/// <returns>Archivo PDF resultante</returns>
|
||||
[HttpGet("GenerarFormulario")]
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
public IActionResult GenerarFormulario(
|
||||
[FromQuery] string claveFormulario,
|
||||
[FromQuery] string idPersona,
|
||||
[FromQuery] string Motivo,
|
||||
[FromQuery] string texto1,
|
||||
[FromQuery] string texto2,
|
||||
[FromQuery] string FechaEfecto,
|
||||
[FromQuery] string Organo,
|
||||
[FromQuery] string FechaEmision,
|
||||
[FromQuery] string Extra)
|
||||
{
|
||||
var pdfBytes = _servicioFormularios.GenerarFormulario(
|
||||
claveFormulario,
|
||||
idPersona,
|
||||
Motivo,
|
||||
texto1,
|
||||
texto2,
|
||||
FechaEfecto,
|
||||
Organo,
|
||||
FechaEmision,
|
||||
Extra);
|
||||
|
||||
if (pdfBytes == null || pdfBytes.Length == 0)
|
||||
return NotFound("No se pudo generar el formulario.");
|
||||
|
||||
return File(pdfBytes, "application/pdf", "formulario.pdf");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class GRUPOController : GenericoController<GRUPO, int>
|
||||
{
|
||||
public GRUPOController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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 GRUPOSENUMERACIONESController : GenericoController<GRUPOSENUMERACIONES, int>
|
||||
{
|
||||
public GRUPOSENUMERACIONESController()
|
||||
: base()
|
||||
{
|
||||
Debug.WriteLine("aqui");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using bdAntifraude.dbcontext;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.DTOs;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using bdAntifraude.db;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serialize.Linq.Serializers;
|
||||
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public abstract class GenericoController<TEntity, TKey> : ControllerBase where TEntity : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Obtiene todos los registros de la entidad (Solo Lectura).
|
||||
/// </summary>
|
||||
/// <returns>Lista de entidades.</returns>
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet]
|
||||
public virtual async Task<IActionResult> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Asegúrate de pasar UseLazyLoadingProxies: false para desactivar Lazy Loading
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var dbSet = context.Set<TEntity>();
|
||||
var entities = await dbSet.AsNoTracking().ToListAsync();
|
||||
//string jsonString = JsonSerializer.Serialize(entities);
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene un registro específico por ID (Solo Lectura).
|
||||
/// </summary>
|
||||
/// <param name="id">ID de la entidad.</param>
|
||||
/// <returns>Entidad encontrada.</returns>
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public virtual IActionResult GetById(TKey id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var dbSet = context.Set<TEntity>();
|
||||
var entity = dbSet.Find(id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")]
|
||||
public virtual async Task<IActionResult> Filtrar([FromBody] ExpressionWrapper request)
|
||||
{
|
||||
IQueryable<TEntity>? query;
|
||||
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<TEntity, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
|
||||
// Aplicar el filtro en la consulta
|
||||
query = context.Set<TEntity>().Where(deserializedExpression);
|
||||
|
||||
|
||||
|
||||
// Agregar un log para verificar el SQL generado y la consulta
|
||||
Console.WriteLine(query.ToQueryString()); // Esto imprime la consulta SQL generada por EF Core
|
||||
|
||||
var res = await query.AsNoTracking().ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (res.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar-entidad")]
|
||||
public virtual async Task<IActionResult> FiltrarEntidad([FromBody] ExpressionWrapper request)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var serializer = new ExpressionSerializer(new Serialize.Linq.Serializers.JsonSerializer());
|
||||
var deserializedExpression = serializer.DeserializeText(request.Expression) as Expression<Func<TEntity, bool>>;
|
||||
|
||||
if (deserializedExpression == null)
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
|
||||
var entity = await context.Set<TEntity>()
|
||||
.Where(deserializedExpression)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (entity == null)
|
||||
return NotFound("No se encontró ninguna entidad que coincida con el filtro.");
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar-Atributo")]
|
||||
public virtual async Task<IActionResult> FiltrarAtributoDinamico([FromBody] ExpressionWrapperAtributo request)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var serializer = new ExpressionSerializer(new Serialize.Linq.Serializers.JsonSerializer());
|
||||
var expression = serializer.DeserializeText(request.Expression) as Expression<Func<TEntity, bool>>;
|
||||
if (expression == null)
|
||||
return BadRequest("La expresión es nula o incorrecta.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.AttributeName))
|
||||
return BadRequest("El nombre del atributo es obligatorio.");
|
||||
|
||||
var parameter = Expression.Parameter(typeof(TEntity), "x");
|
||||
var property = Expression.PropertyOrField(parameter, request.AttributeName);
|
||||
|
||||
if (property == null)
|
||||
return BadRequest($"El atributo '{request.AttributeName}' no existe en la entidad.");
|
||||
|
||||
// Crear una expresión para seleccionar el atributo
|
||||
var attributeSelector = Expression.Lambda<Func<TEntity, object>>(
|
||||
Expression.Convert(property, typeof(object)),
|
||||
parameter);
|
||||
|
||||
var entities = await context.Set<TEntity>()
|
||||
.Where(expression)
|
||||
.Select(attributeSelector)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Crea una nueva entidad (Escritura).
|
||||
/// </summary>
|
||||
/// <param name="entity">Entidad a crear.</param>
|
||||
/// <returns>Entidad creada.</returns>
|
||||
/// <summary>
|
||||
/// Crea una nueva entidad (Escritura).
|
||||
/// </summary>
|
||||
/// <param name="entity">Entidad a crear.</param>
|
||||
/// <returns>Entidad creada.</returns>
|
||||
[Authorize(Policy = "SupervisorPolicy")]
|
||||
[HttpPost]
|
||||
public virtual IActionResult Create([FromBody] TEntity entity)
|
||||
{
|
||||
// Validación automática: mantenemos tu comportamiento original
|
||||
if (!TryValidateModel(entity))
|
||||
ModelState.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
using var context = tsGestionAntifraude.NuevoContexto(
|
||||
SoloLectura: false,
|
||||
UseLazyLoadingProxies: false
|
||||
);
|
||||
var dbSet = context.Set<TEntity>();
|
||||
|
||||
// 1) Creamos una instancia vacía y la añadimos al contexto
|
||||
var newEntity = Activator.CreateInstance<TEntity>();
|
||||
dbSet.Add(newEntity);
|
||||
|
||||
// 2) Obtenemos el metadata de EF Core para TEntity
|
||||
var efEntityType = context.Model.FindEntityType(typeof(TEntity));
|
||||
if (efEntityType == null)
|
||||
throw new InvalidOperationException($"No se encontró metadata EF para {typeof(TEntity).Name}");
|
||||
|
||||
foreach (var prop in typeof(TEntity)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
// Solo las que EF Core mapea a columna
|
||||
if (efEntityType.FindProperty(prop.Name) != null)
|
||||
{
|
||||
var valor = prop.GetValue(entity);
|
||||
context.Entry(newEntity)
|
||||
.Property(prop.Name)
|
||||
.CurrentValue = valor;
|
||||
}
|
||||
}
|
||||
|
||||
// 4) Guardamos
|
||||
context.SaveChanges();
|
||||
|
||||
// 5) Devolvemos CreatedAtAction con el ID recién generado
|
||||
var id = GetEntityId(newEntity);
|
||||
if (id != null)
|
||||
return CreatedAtAction(nameof(GetById), new { id }, newEntity);
|
||||
|
||||
return Ok(newEntity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actualiza una entidad existente (Escritura).
|
||||
/// </summary>
|
||||
/// <param name="id">ID de la entidad a actualizar.</param>
|
||||
/// <param name="entity">Entidad actualizada.</param>
|
||||
/// <returns>No content.</returns>
|
||||
[Authorize(Policy = "SupervisorPolicy")]
|
||||
[HttpPut("{id}")]
|
||||
public virtual IActionResult Update(TKey id, [FromBody] TEntity entity)
|
||||
{
|
||||
var entityId = GetEntityId(entity);
|
||||
if (entityId == null || !id.Equals((TKey)entityId))
|
||||
return BadRequest("El ID de la entidad no coincide con el ID de la URL.");
|
||||
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: false, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var dbSet = context.Set<TEntity>();
|
||||
|
||||
// Buscar la entidad existente
|
||||
var existingEntity = dbSet.Find(id);
|
||||
if (existingEntity == null)
|
||||
return NotFound("No se encontró la entidad para actualizar.");
|
||||
|
||||
// Iterar sobre las propiedades de la entidad
|
||||
foreach (var property in typeof(TEntity).GetProperties())
|
||||
{
|
||||
// Verificar si la propiedad es escalar o navegación
|
||||
var propertyMetadata = context.Model.FindEntityType(typeof(TEntity))?
|
||||
.FindProperty(property.Name);
|
||||
|
||||
if (propertyMetadata == null)
|
||||
{
|
||||
// Es una propiedad de navegación, omitirla
|
||||
continue;
|
||||
}
|
||||
|
||||
// Manejar propiedades escalares
|
||||
var newValue = property.GetValue(entity);
|
||||
var oldValue = property.GetValue(existingEntity);
|
||||
|
||||
if (!Equals(newValue, oldValue))
|
||||
{
|
||||
context.Entry(existingEntity).Property(property.Name).CurrentValue = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Guardar cambios
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina una entidad por ID (Escritura).
|
||||
/// </summary>
|
||||
/// <param name="id">ID de la entidad a eliminar.</param>
|
||||
/// <returns>No content.</returns>
|
||||
[Authorize(Policy = "SupervisorPolicy")]
|
||||
[HttpDelete("{id}")]
|
||||
public virtual IActionResult Delete(TKey id)
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: false, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var dbSet = context.Set<TEntity>();
|
||||
var entity = dbSet.Find(id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
dbSet.Remove(entity);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene el valor de la propiedad de ID de la entidad.
|
||||
/// </summary>
|
||||
/// <param name="entity">Entidad de la cual obtener el ID.</param>
|
||||
/// <returns>Valor del ID.</returns>
|
||||
protected virtual object GetEntityId(TEntity entity)
|
||||
{
|
||||
// Busca las propiedades que podrían ser claves primarias según las convenciones o el atributo [Key]
|
||||
var type = typeof(TEntity);
|
||||
|
||||
// Primero, buscamos cualquier propiedad marcada con [Key], que es la forma más confiable de identificar el ID
|
||||
var idProperty = type.GetProperties().FirstOrDefault(p => p.GetCustomAttribute<KeyAttribute>() != null);
|
||||
|
||||
if (idProperty != null)
|
||||
{
|
||||
return idProperty.GetValue(entity);
|
||||
}
|
||||
|
||||
// Si no hay un atributo [Key], intentamos con algunas convenciones de nombres comunes para ID
|
||||
idProperty = type.GetProperties().FirstOrDefault(p =>
|
||||
p.Name.Equals("ID", StringComparison.OrdinalIgnoreCase) || // Nombre genérico 'Id'
|
||||
p.Name.Equals($"{type.Name}ID", StringComparison.OrdinalIgnoreCase) || //
|
||||
p.Name.StartsWith("ID", StringComparison.OrdinalIgnoreCase)); // Cualquier nombre que comience con 'ID'
|
||||
|
||||
if (idProperty != null)
|
||||
{
|
||||
return idProperty.GetValue(entity);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("No se pudo encontrar una propiedad de ID para la entidad.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ExpressionWrapper
|
||||
{
|
||||
public string Expression { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ExpressionWrapperAtributo
|
||||
{
|
||||
public string Expression { get; set; }
|
||||
public string AttributeName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class IDIOMASController : GenericoController<IDIOMAS, int>
|
||||
{
|
||||
public IDIOMASController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetWithIncludes/{id}")]
|
||||
public async Task<IActionResult> GetWithIncludes(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.IDIOMAS
|
||||
.Include(p => p.IDNIVELNavigation)
|
||||
.Include(p => p.IDTIPOIDIOMANavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDPERSONA == id).ToListAsync();
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using bdAntifraude.dbcontext;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.DTOs;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using bdAntifraude.db;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serialize.Linq.Serializers;
|
||||
using SwaggerAntifraude.Controllers;
|
||||
|
||||
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class INCIDENCIASController : GenericoController<INCIDENCIAS, int>
|
||||
{
|
||||
public INCIDENCIASController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")]
|
||||
public override async Task<IActionResult> Filtrar([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<INCIDENCIAS, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.INCIDENCIAS.Where(deserializedExpression)
|
||||
.Include(v => v.IDPERSONANavigation)
|
||||
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using bdAntifraude.dbcontext;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.DTOs;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using bdAntifraude.db;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.IO;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class LINEASVIDAADMINISTRATIVAController : GenericoController<LINEASVIDAADMINISTRATIVA, int>
|
||||
{
|
||||
public LINEASVIDAADMINISTRATIVAController() : base() { }
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("LineasVidaAdminGrid")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public virtual async Task<IActionResult> LineasVidaAdminGrid([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<LINEASVIDAADMINISTRATIVA, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var entities = await context.Set<LINEASVIDAADMINISTRATIVA>()
|
||||
.Where(deserializedExpression)
|
||||
.Include(v => v.IDVIDAADMINNavigation) // Incluyendo la navegación principal
|
||||
.Include(v => v.IDTIPONavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<PUESTOS>();
|
||||
var entity = context.LINEASVIDAADMINISTRATIVA
|
||||
.Include(v => v.IDVIDAADMINNavigation)
|
||||
.ThenInclude(m => m.IDPERSONALNavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDLINEAVIDAADMIN == id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("LineasVidaAdminGridbyId/{idVida}")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public async Task<IActionResult> LineasVidaAdminGridbyId(int idVida)
|
||||
{
|
||||
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<LINEASVIDAADMINISTRATIVA, bool>>;
|
||||
//if (deserializedExpression == null)
|
||||
//{
|
||||
// return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
//}
|
||||
|
||||
|
||||
|
||||
var entities = await context.Set<LINEASVIDAADMINISTRATIVA>()
|
||||
.Where(x => x.IDVIDAADMIN == idVida)
|
||||
.Include(v => v.IDVIDAADMINNavigation) // Incluyendo la navegación principal
|
||||
.Include(v => v.IDTIPONavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class MOTIVOS_ADMINISTRATIVOSController : GenericoController<MOTIVOS_ADMINISTRATIVOS, int>
|
||||
{
|
||||
public MOTIVOS_ADMINISTRATIVOSController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("TiposExtend/{idMotivo}")]
|
||||
public async Task<IActionResult> TiposExtend(int idMotivo)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var motAdmin = context.MOTIVOS_ADMINISTRATIVOS.Include(v => v.IDTIPOAPTOSNavigation).FirstOrDefault(p => p.IDMOTIVO == idMotivo);
|
||||
if (motAdmin == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(motAdmin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("TiposExtend")]
|
||||
public async Task<IActionResult> TiposExtend()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var motAdmin = await context.MOTIVOS_ADMINISTRATIVOS.Include(v => v.IDTIPOAPTOSNavigation).AsNoTracking().ToListAsync();
|
||||
if (motAdmin == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(motAdmin);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class NIVELController : GenericoController<NIVEL, int>
|
||||
{
|
||||
public NIVELController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.Controllers;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class NOMINASController : GenericoController<NOMINAS, int>
|
||||
{
|
||||
public NOMINASController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public override async Task<IActionResult> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var entities = await context.NOMINAS
|
||||
.Include(x => x.IDTIPONavigation)
|
||||
.Include(x => x.IDSITUACIONNOMINANavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<VIDA_ADMINISTRATIVA>();
|
||||
var entities = context.NOMINAS
|
||||
.Include(x => x.IDTIPONavigation)
|
||||
.Include(x => x.IDSITUACIONNOMINANavigation)
|
||||
//.Include(x => x.NOMINATRABAJADORCABECERA)
|
||||
//.ThenInclude(pr => pr.IDPERSONANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDNOMINAS == id);
|
||||
|
||||
|
||||
|
||||
if (entities == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public override async Task<IActionResult> Filtrar([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<NOMINAS, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.NOMINAS.Where(deserializedExpression)
|
||||
//.Include(m => m.IDMOTIVOADMINISTRATIVONavigation)
|
||||
//.ThenInclude(aa => aa.IDTIPOAPTOSNavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class NOMINATRABAJADORCABECERAController : GenericoController<NOMINATRABAJADORCABECERA, int>
|
||||
{
|
||||
public NOMINATRABAJADORCABECERAController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<VIDA_ADMINISTRATIVA>();
|
||||
var entities = context.NOMINATRABAJADORCABECERA
|
||||
.Include(x => x.IDPERSONANavigation)
|
||||
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDNOMINATRABAJADOR == id);
|
||||
|
||||
|
||||
|
||||
if (entities == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public override async Task<IActionResult> Filtrar([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<NOMINATRABAJADORCABECERA, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.NOMINATRABAJADORCABECERA.Where(deserializedExpression)
|
||||
.Include(x => x.IDPERSONANavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class OCUPACIONController : GenericoController<OCUPACION, int>
|
||||
{
|
||||
public OCUPACIONController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using bdAntifraude.dbcontext;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.DTOs;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using bdAntifraude.db;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serialize.Linq.Serializers;
|
||||
using SwaggerAntifraude.Controllers;
|
||||
|
||||
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PERSONASController : GenericoController<PERSONAS, int>
|
||||
{
|
||||
public PERSONASController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public override async Task<IActionResult> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var entities = await context.PERSONAS
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(rpt => rpt.IDRPTNavigation)
|
||||
.ThenInclude(sit => sit.IDSITUACIONNavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(ocu => ocu.IDOCUPACIONNavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(rpt => rpt.IDRPTDESNavigation)
|
||||
.ThenInclude(rpt => rpt.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.Include(cp => cp.IDDEPARTAMENTONavigation)
|
||||
.Include(cp => cp.CODIGOMUNICIPIONavigation)
|
||||
.ThenInclude(cpro => cpro.CODIGOPROVINCIANavigation)
|
||||
.Include(cp => cp.IDSITUACIONACTUALIRPFNavigation)
|
||||
.Include(cp => cp.CODIGOMUNICIPIONavigation)
|
||||
.Include(cp=>cp.IDTIPONavigation)
|
||||
.Include(cp=>cp.IDDEPARTAMENTONavigation)
|
||||
.Include(cp => cp.IDSEXONavigation)
|
||||
.Include(cp => cp.INCIDENCIAS)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("PersonaNominaNif/{nif}")]
|
||||
public IActionResult GetByNifNom(string nif)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var persona = context.PERSONAS.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(rpt => rpt.IDRPTNavigation)
|
||||
.ThenInclude(sit => sit.IDSITUACIONNavigation)
|
||||
.Include(pue => pue.IDSEXONavigation)
|
||||
.Include(pue => pue.IDTIPONavigation)
|
||||
.Include(pue => pue.IDNIVELRPTNavigation)
|
||||
.Include(pue => pue.ASCENDIENTES)
|
||||
.ThenInclude(dis => dis.IDDISCAPACIDADNavigation)
|
||||
.Include(pue => pue.HIJOS)
|
||||
.ThenInclude(dis => dis.IDDISCAPACIDADNavigation)
|
||||
.Include(pue => pue.DIFERENCIAPAGODELEGADO)
|
||||
.Include(pue => pue.DIFERENCIATRIENIOS)
|
||||
.Include(pue => pue.REDUCCIONDEJORNADA)
|
||||
.Include(pue => pue.TRABAJADORTIEMPOPARCIAL)
|
||||
.Include(cp => cp.ENFERMEDADES)
|
||||
.ThenInclude(y => y.IDTIPONavigation)
|
||||
.Include(cp => cp.MATERNIDADES)
|
||||
.Include(cp=>cp.IDOCUPACIONNavigation)
|
||||
.Include(cp => cp.HUELGAS)
|
||||
.ThenInclude(cpro => cpro.IDNOMINAORIGENDATOSNavigation)
|
||||
.Include(cp => cp.HUELGAS)
|
||||
.ThenInclude(cpro => cpro.IDNOMINAAPLICACIONNavigation)
|
||||
.Include(cp => cp.INCIDENCIAS)
|
||||
.ThenInclude(idnom => idnom.IDNOMINANavigation)
|
||||
.Include(cp => cp.INCIDENCIAS)
|
||||
.ThenInclude(idnom => idnom.IDCONCEPTONOMINANavigation)
|
||||
.Include(n => n.NOMINATRABAJADORCABECERA)
|
||||
.ThenInclude(pr => pr.IDNOMINANavigation)
|
||||
.Include(pue=>pue.OTRASRETRIBUCIONES)
|
||||
.Include(cp => cp.PERMISOSSINRETRIBUCION)
|
||||
.ThenInclude(cpro => cpro.IDNOMINAORIGENDEDATOSNavigation)
|
||||
.Include(cp => cp.PERMISOSSINRETRIBUCION)
|
||||
.ThenInclude(cpro => cpro.IDNOMINAAPLICACIONNavigation)
|
||||
.Include(pue => pue.PRESTAMOS)
|
||||
.ThenInclude(pre=>pre.IDNOMINAINICIONavigation)
|
||||
.Include(cp => cp.PUESTOSTRABAJO)
|
||||
.ThenInclude(cpro => cpro.IDTIPOPUESTOTRABAJONavigation)
|
||||
.Include(cp => cp.PUESTOSTRABAJO)
|
||||
.ThenInclude(cpro => cpro.IDGRUPOFUNCIONARIONavigation)
|
||||
.Include(pue=> pue.REDUCCIONDEJORNADA)
|
||||
.Include(pue=> pue.RETENCIONJUDICIAL)
|
||||
.ThenInclude(ret=>ret.IDPLANTILLANavigation)
|
||||
.Include(pue=>pue.PRODUCTIVIDAD)
|
||||
.Include(pue => pue.IDSITUACIONACTUALIRPFNavigation)
|
||||
.ThenInclude(situ => situ.IDDISCAPACIDADNavigation)
|
||||
.Include(pue => pue.IDSITUACIONACTUALIRPFNavigation)
|
||||
.ThenInclude(situ => situ.IDSITUACIONFAMILIARNavigation)
|
||||
.Include(pue => pue.IDSITUACIONACTUALIRPFNavigation)
|
||||
.ThenInclude(situ => situ.IDSITUACIONLABORALNavigation)
|
||||
.Include(pue => pue.IDSITUACIONACTUALIRPFNavigation)
|
||||
.ThenInclude(situ => situ.IDCONTRATOORELACIONNavigation)
|
||||
.Include(pue => pue.HISTORICOIRPF)
|
||||
.Include(pue => pue.IDMUTUANavigation)
|
||||
.Include(pue => pue.IDMUTUA2Navigation)
|
||||
.Include(pue => pue.IDPUESTOTRABAJOOPOSICIONNavigation)
|
||||
.Include(pue => pue.IDCAUSABAJAPARNavigation)
|
||||
.Include(pue => pue.IDCONTRATONavigation)
|
||||
.Include(pue => pue.IDGRUPOFUNCIONARIONavigation)
|
||||
.Include(pue => pue.IDCUENTACOTIZACIONPATRONALNavigation)
|
||||
.Include(pue => pue.IDDEPARTAMENTONavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(ocu => ocu.IDOCUPACIONNavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(rpt => rpt.IDRPTDESNavigation)
|
||||
.ThenInclude(rpt => rpt.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.Include(pue => pue.EXCEPCIONESPERMISOSIDPERSONANavigation)
|
||||
.ThenInclude(exc=>exc.IDDEPARTAMENTONavigation)
|
||||
.Include(pue => pue.EXCEPCIONESPERMISOSIDPERSONANavigation)
|
||||
.ThenInclude(exc => exc.IDPERSONAPERMISONavigation)
|
||||
.Include(cp=>cp.DIFERENCIAPAGODELEGADO)
|
||||
.Include(cp => cp.IDDEPARTAMENTONavigation)
|
||||
.Include(cp => cp.CODIGOMUNICIPIONavigation)
|
||||
.ThenInclude(cpro => cpro.CODIGOPROVINCIANavigation)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefault(p => p.NIF == nif);
|
||||
if (persona == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(persona);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("nif/{nif}")]
|
||||
public IActionResult GetByNif(string nif)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var persona = context.PERSONAS.Include(pue=> pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(rpt => rpt.IDRPTNavigation)
|
||||
.ThenInclude(sit=> sit.IDSITUACIONNavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(ocu => ocu.IDOCUPACIONNavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
.ThenInclude(rpt => rpt.IDRPTDESNavigation)
|
||||
.ThenInclude(rpt => rpt.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(pue => pue.PUESTOSIDPERSONALNavigation)
|
||||
//.Include(n => n.NOMINATRABAJADORCABECERA)
|
||||
//.ThenInclude(pr => pr.IDPERSONANavigation)
|
||||
.Include(cp => cp.IDDEPARTAMENTONavigation)
|
||||
.Include(cp => cp.CODIGOMUNICIPIONavigation)
|
||||
.ThenInclude(cpro => cpro.CODIGOPROVINCIANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(p => p.NIF == nif);
|
||||
if (persona == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(persona);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("getPersonaVidaAdm")]
|
||||
public virtual async Task<IActionResult> getPersonaVidaAdm([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<PERSONAS, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
|
||||
var entities = await context.Set<PERSONAS>()
|
||||
.Where(deserializedExpression)
|
||||
.Include(v => v.IDGRADOPERSONALCONSOLIDADONavigation) // Incluyendo la navegación principal
|
||||
.Include(v => v.IDNIVELRPTNavigation)
|
||||
.Include(v => v.IDGRUPOFUNCIONARIONavigation)
|
||||
.Include(v => v.IDTIPONavigation)
|
||||
.Include(cp => cp.IDDEPARTAMENTONavigation)
|
||||
.Include(v => v.IDADSCRIPCIONRPTNavigation)
|
||||
.Include(v => v.IDCUERPORPTNavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities.First());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")]
|
||||
public override async Task<IActionResult> Filtrar([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<PERSONAS, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.PERSONAS.Where(deserializedExpression)
|
||||
.Include(v => v.IDSITUACIONADMINISTRATIVARPTNavigation)
|
||||
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PROVISIONController : GenericoController<PROVISION, int>
|
||||
{
|
||||
public PROVISIONController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using bdAntifraude.dbcontext;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using SwaggerAntifraude.DTOs;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using bdAntifraude.db;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.IO;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PUESTOSController : GenericoController<PUESTOS, int>
|
||||
{
|
||||
public PUESTOSController() : base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("getActivos")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public virtual async Task<IActionResult> getActivos([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<PUESTOS, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
|
||||
|
||||
var entities = await context.Set<PUESTOS>()
|
||||
.Where(deserializedExpression)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.IDNIVEL_RPTNavigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.IDRPTNavigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.GRUPO1Navigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.CUERPO1Navigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(r => r.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(v => v.IDRPTNavigation)
|
||||
.ThenInclude(x => x.IDSITUACIONNavigation)
|
||||
.Include(v => v.IDOCUPACIONNavigation)
|
||||
.Include(v => v.IDDOTACIONNavigation)
|
||||
.Include(i => i.IDRPTDESNavigation)
|
||||
.ThenInclude(r => r.IDDEPARTAMENTONavigation)
|
||||
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
//var entities = await context.Set<PUESTOS>()
|
||||
// .Where(deserializedExpression)
|
||||
// .Include(v => v.IDRPTDESNavigation) // Incluyendo la navegación principal
|
||||
// .ThenInclude(m => m.IDNIVEL_RPTNavigation) // Incluye la navegación hacia IDNIVEL_RPT
|
||||
// .Include(v => v.IDRPTDESNavigation)
|
||||
// .ThenInclude(m => m.GRUPO1Navigation) // Incluye la navegación hacia GRUPO1
|
||||
// .Include(v => v.IDRPTDESNavigation)
|
||||
// .ThenInclude(m => m.CUERPO1Navigation) // Incluye la navegación hacia CUERPO1
|
||||
// .Include(v => v.IDRPTNavigation)
|
||||
// .ThenInclude(x => x.IDSITUACIONNavigation) // Incluye la navegación hacia IDSITUACION
|
||||
// .Include(v => v.IDOCUPACIONNavigation)
|
||||
// .AsNoTracking()
|
||||
// .ToListAsync();
|
||||
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetWithIncludes/{id}")]
|
||||
public async Task<IActionResult> GetWithIncludes(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.PUESTOS
|
||||
.Include(p => p.IDDOTACIONNavigation) // Carga Dotación
|
||||
.Include(p => p.IDPERSONALNavigation) // Carga Persona asociada
|
||||
.Include(p => p.IDOCUPACIONNavigation) // Carga Ocupación
|
||||
.Include(p => p.TITULARNavigation) // Carga Titular
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDRPTDES == id).ToListAsync(); // Filtra por IDPUESTO
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<PUESTOS>();
|
||||
var entity = context.PUESTOS
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.IDNIVEL_RPTNavigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.IDRPTNavigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.GRUPO1Navigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(m => m.CUERPO1Navigation)
|
||||
.Include(v => v.IDRPTDESNavigation)
|
||||
.ThenInclude(r => r.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(v => v.IDRPTNavigation)
|
||||
.ThenInclude(x => x.IDSITUACIONNavigation)
|
||||
.Include(v => v.IDOCUPACIONNavigation)
|
||||
.Include(v => v.IDDOTACIONNavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDPUESTO == id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class RETRIBUCIONBASICAController : GenericoController<RETRIBUCIONBASICA, int>
|
||||
{
|
||||
public RETRIBUCIONBASICAController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SwaggerAntifraude.Controllers;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class RPTController : GenericoController<RPT, int>
|
||||
{
|
||||
public RPTController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<IActionResult> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var rpts = context.RPT
|
||||
.Include(r => r.IDSITUACIONNavigation).ToList();
|
||||
|
||||
if (rpts == null)
|
||||
return NotFound("Sin registros.");
|
||||
|
||||
return Ok(rpts);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class RPT_DESCRIPController : GenericoController<RPT_DESCRIP, int>
|
||||
{
|
||||
public RPT_DESCRIPController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<VIDA_ADMINISTRATIVA>();
|
||||
var entities = context.RPT_DESCRIP
|
||||
.Include(rd => rd.IDRPTNavigation)
|
||||
.Include(rd => rd.GRUPO1Navigation)
|
||||
.Include(rd => rd.IDUNIDADADMINISTRATIVANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDRPTDES == id);
|
||||
|
||||
|
||||
|
||||
if (entities == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetWithIncludes/{id}")]
|
||||
public async Task<IActionResult> GetWithIncludes(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.RPT_DESCRIP
|
||||
.Include(p => p.IDRPTNavigation)
|
||||
.Include(p => p.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(p => p.CUERPO1Navigation)
|
||||
.Include(p => p.GRUPO1Navigation)
|
||||
.Include(p => p.GRUPO2Navigation)
|
||||
.Include(p => p.IDDEPARTAMENTONavigation)
|
||||
.Include(p => p.ADSCRIPCIONNavigation)
|
||||
.Include(p => p.PROVISIONNavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDRPT == id).ToListAsync(); // Filtra por IDPUESTO
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetAtributo/{id}/{id2}")]
|
||||
public async Task<IActionResult> GetListRPTGrupo(int id, int id2)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.RPT_DESCRIP
|
||||
.Include(p => p.GRUPO1Navigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDRPT == id && p.GRUPO1 == id2).Select(x => x.CODIGO).ToListAsync(); // Filtra por IDPUESTO
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using SwaggerAntifraude.Models;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ResultadoIdentificacionController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Carga el perfil de identificación y las incidencias asociadas para el usuario especificado.
|
||||
/// Se asignan roles y se consultan incidencias según el origen (WEBINTRANET, GESTDELE o RPT).
|
||||
/// Además, se incluyen en el listado tanto el usuario consultante como sus subordinados,
|
||||
/// forzando que el usuario consultante se agregue a la lista (incluso si ya apareciera en el listado de subordinados).
|
||||
/// </summary>
|
||||
/// <param name="nif">NIF del usuario a identificar.</param>
|
||||
/// <param name="origen">Origen de la consulta (por ejemplo: "WEBINTRANET", "GESTDELE" o "RPT").</param>
|
||||
/// <returns>Objeto ResultadoIdentificacion con la lista de perfiles e incidencias.</returns>
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("nif/{nif}/origen/{origen}")]
|
||||
public IActionResult CargaPerfilIdentificacion(string nif, string origen)
|
||||
{
|
||||
var resultadoIdentificacion = new ResultadoIdentificacion
|
||||
{
|
||||
Personas = new List<Personal>()
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Se busca la persona por NIF
|
||||
var persona = context.PERSONAS
|
||||
.Include(p => p.IDDEPARTAMENTONavigation) // Para obtener la descripción del departamento
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(p => p.NIF.Trim().ToUpper() == nif.Trim().ToUpper());
|
||||
|
||||
if (persona == null)
|
||||
{
|
||||
resultadoIdentificacion.resultado = 1;
|
||||
resultadoIdentificacion.errores = $"No se encontró persona con NIF: {nif}";
|
||||
return Ok(resultadoIdentificacion);
|
||||
}
|
||||
|
||||
// Creamos el objeto Personal para el usuario consultante
|
||||
var usuarioActual = new Personal
|
||||
{
|
||||
Nombre = persona.APELLIDOS + ", " + persona.NOMBRE,
|
||||
Departamento = persona.IDDEPARTAMENTONavigation?.DESCRIPCION,
|
||||
Dni = persona.NIF,
|
||||
idPersona = persona.IDPERSONA,
|
||||
Roll = string.Empty
|
||||
};
|
||||
|
||||
// Creamos la lista de personas y agregamos inmediatamente el usuario consultante
|
||||
var personas = new List<Personal>();
|
||||
personas.Add(usuarioActual);
|
||||
resultadoIdentificacion.Personas = personas;
|
||||
|
||||
// Lógica de asignación de roles según el origen
|
||||
if (origen == "WEBINTRANET" || origen == "GESTDELE")
|
||||
{
|
||||
if (persona.DELEGADO)
|
||||
usuarioActual.Roll = "DELEGADO";
|
||||
if (persona.SUPERVISORDEPARTAMENTO)
|
||||
usuarioActual.Roll = "SUPERVISOR";
|
||||
if (persona.SUPERVISORDETODO)
|
||||
usuarioActual.Roll = "SUPERVISORDETODO";
|
||||
if (persona.ADMINISTRADORCONTROLHORARIO)
|
||||
usuarioActual.Roll = "ADMINISTRADORCONTROLHORARIO";
|
||||
|
||||
// Consultar incidencias en la vista V_ASISTENCIAS_EXTENDIDA
|
||||
List<V_ASISTENCIAS_EXTENDIDA> asisYestados;
|
||||
if (usuarioActual.Roll == "ADMINISTRADORCONTROLHORARIO")
|
||||
{
|
||||
asisYestados = context.V_ASISTENCIAS_EXTENDIDA
|
||||
.Where(x => x.ULTIMOESTADO.Contains("VISTO BUENO") || x.ULTIMOESTADO == "SOLICITADA")
|
||||
.ToList();
|
||||
}
|
||||
else if (usuarioActual.Roll == "SUPERVISORDETODO")
|
||||
{
|
||||
asisYestados = context.V_ASISTENCIAS_EXTENDIDA
|
||||
.Where(x => x.ULTIMOESTADO.Contains("PROPUESTA") ||
|
||||
x.ULTIMOESTADO == "SOLICITADA" ||
|
||||
x.ULTIMOESTADO.Contains("VISTO BUENO"))
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
asisYestados = context.V_ASISTENCIAS_EXTENDIDA
|
||||
.Where(x => x.ULTIMOESTADO.Contains("PROPUESTA"))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
var asisBorrador = context.V_ASISTENCIAS_EXTENDIDA
|
||||
.Where(x => x.ULTIMOESTADO == "BORRADOR")
|
||||
.ToList();
|
||||
|
||||
if (!string.IsNullOrEmpty(usuarioActual.Roll))
|
||||
{
|
||||
if (usuarioActual.Roll != "ADMINISTRADORCONTROLHORARIO")
|
||||
{
|
||||
// Para SUPERVISOR o DELEGADO se filtra por departamento
|
||||
if (usuarioActual.Roll == "SUPERVISOR" || usuarioActual.Roll == "DELEGADO")
|
||||
{
|
||||
asisYestados = asisYestados
|
||||
.Where(x => x.IDDEPARTAMENTO == persona.IDDEPARTAMENTO)
|
||||
.ToList();
|
||||
}
|
||||
usuarioActual.NumeroInciPorAceptar = asisYestados.Count;
|
||||
usuarioActual.NumeroInciBorrador = asisBorrador
|
||||
.Where(x => x.IDPERSONA == usuarioActual.idPersona)
|
||||
.Count();
|
||||
|
||||
if (usuarioActual.NumeroInciPorAceptar > 0)
|
||||
{
|
||||
usuarioActual.FeIniInciPorAceptar = (DateTime)asisYestados
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.First().FECHAOCURRENCIA;
|
||||
usuarioActual.FeFinInciPorAceptar = (DateTime)asisYestados
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.Last().FECHAOCURRENCIA;
|
||||
}
|
||||
if (usuarioActual.NumeroInciBorrador > 0)
|
||||
{
|
||||
usuarioActual.FeIniInciBorrador = (DateTime)asisBorrador
|
||||
.Where(x => x.IDPERSONA == usuarioActual.idPersona)
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.First().FECHAOCURRENCIA;
|
||||
usuarioActual.FeFinInciBorrador = (DateTime)asisBorrador
|
||||
.Where(x => x.IDPERSONA == usuarioActual.idPersona)
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.Last().FECHAOCURRENCIA;
|
||||
}
|
||||
}
|
||||
else // Caso ADMINISTRADORCONTROLHORARIO
|
||||
{
|
||||
asisYestados = context.V_ASISTENCIAS_EXTENDIDA
|
||||
.Where(x => x.ULTIMOESTADO == "VISTO BUENO")
|
||||
.ToList();
|
||||
usuarioActual.NumeroInciPorAceptar = asisYestados.Count;
|
||||
usuarioActual.NumeroInciBorrador = asisBorrador.Count;
|
||||
if (usuarioActual.NumeroInciPorAceptar > 0)
|
||||
{
|
||||
usuarioActual.FeIniInciPorAceptar = (DateTime)asisYestados
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.First().FECHAOCURRENCIA;
|
||||
usuarioActual.FeFinInciPorAceptar = (DateTime)asisYestados
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.Last().FECHAOCURRENCIA;
|
||||
}
|
||||
if (usuarioActual.NumeroInciBorrador > 0)
|
||||
{
|
||||
usuarioActual.FeIniInciBorrador = (DateTime)asisBorrador
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.First().FECHAOCURRENCIA;
|
||||
usuarioActual.FeFinInciBorrador = (DateTime)asisBorrador
|
||||
.OrderBy(x => x.FECHAOCURRENCIA)
|
||||
.Last().FECHAOCURRENCIA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cargar perfiles secundarios (subordinados)
|
||||
if (!string.IsNullOrEmpty(usuarioActual.Roll))
|
||||
{
|
||||
var lpdep = context.PERSONAS
|
||||
.Include(p => p.IDDEPARTAMENTONavigation)
|
||||
.Where(x => x.IDDEPARTAMENTO != null && x.FECHABAJA == null)
|
||||
.ToList();
|
||||
|
||||
if (usuarioActual.Roll == "SUPERVISOR" || usuarioActual.Roll == "DELEGADO")
|
||||
{
|
||||
lpdep = lpdep.Where(x => x.IDDEPARTAMENTO == persona.IDDEPARTAMENTO).ToList();
|
||||
}
|
||||
|
||||
foreach (var perDep in lpdep.OrderBy(x => x.IDDEPARTAMENTO))
|
||||
{
|
||||
if (perDep.NIF.Trim().ToUpper() != nif.Trim().ToUpper() &&
|
||||
(
|
||||
(!perDep.SUPERVISORDEPARTAMENTO && (usuarioActual.Roll == "SUPERVISOR" || usuarioActual.Roll == "DELEGADO"))
|
||||
|| (usuarioActual.Roll == "SUPERVISORDETODO")
|
||||
)
|
||||
)
|
||||
{
|
||||
var subordinate = new Personal
|
||||
{
|
||||
Nombre = perDep.APELLIDOS + ", " + perDep.NOMBRE,
|
||||
Dni = perDep.NIF,
|
||||
idPersona = perDep.IDPERSONA,
|
||||
Departamento = perDep.IDDEPARTAMENTONavigation?.DESCRIPCION,
|
||||
Roll = string.Empty
|
||||
};
|
||||
if (perDep.DELEGADO)
|
||||
subordinate.Roll = "DELEGADO";
|
||||
if (string.IsNullOrEmpty(subordinate.Roll) && perDep.SUPERVISORDEPARTAMENTO)
|
||||
subordinate.Roll = "SUPERVISOR";
|
||||
subordinate.NumeroInciPorAceptar = asisYestados.Where(x => x.IDPERSONA == perDep.IDPERSONA).Count();
|
||||
subordinate.NumeroInciBorrador = asisBorrador.Where(x => x.IDPERSONA == perDep.IDPERSONA).Count();
|
||||
|
||||
personas.Add(subordinate);
|
||||
}
|
||||
}
|
||||
|
||||
// Calcular fechas globales a partir de todos los perfiles (incluyendo el usuario consultante)
|
||||
DateTime fechaNula = new DateTime(1, 1, 1);
|
||||
if (personas.Any(x => x.FeIniInciPorAceptar > fechaNula))
|
||||
{
|
||||
resultadoIdentificacion.FeIniInciPorAceptar = personas
|
||||
.Where(x => x.FeIniInciPorAceptar > fechaNula)
|
||||
.OrderBy(x => x.FeIniInciPorAceptar)
|
||||
.First().FeIniInciPorAceptar;
|
||||
}
|
||||
if (personas.Any(x => x.FeFinInciPorAceptar > fechaNula))
|
||||
{
|
||||
resultadoIdentificacion.FeFinInciPorAceptar = personas
|
||||
.Where(x => x.FeFinInciPorAceptar > fechaNula)
|
||||
.OrderBy(x => x.FeFinInciPorAceptar)
|
||||
.Last().FeFinInciPorAceptar;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Caso "RPT"
|
||||
{
|
||||
if (origen == "RPT" && !persona.ADMINISTRARPTYREGISTRO)
|
||||
{
|
||||
resultadoIdentificacion.resultado = 1;
|
||||
resultadoIdentificacion.errores = "Identificación correcta pero no es Administrador de Rpt y de Registro de Personal";
|
||||
return Ok(resultadoIdentificacion);
|
||||
}
|
||||
}
|
||||
|
||||
resultadoIdentificacion.resultado = 0;
|
||||
resultadoIdentificacion.errores = string.Empty;
|
||||
return Ok(resultadoIdentificacion);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultadoIdentificacion.resultado = 3;
|
||||
resultadoIdentificacion.errores = ex.ToString();
|
||||
return Ok(resultadoIdentificacion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
//[ApiController]
|
||||
//[Route("api/[controller]")]
|
||||
//public class SERVICIOSController : GenericoController<SERVICIOS, int>
|
||||
//{
|
||||
// public SERVICIOSController()
|
||||
// : base()
|
||||
// {
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class SITUACIONController : GenericoController<SITUACION, int>
|
||||
{
|
||||
public SITUACIONController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TIPOAPTOSADMINISTRATIVOSController : GenericoController<TIPOAPTOSADMINISTRATIVOS, int>
|
||||
{
|
||||
public TIPOAPTOSADMINISTRATIVOSController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TIPOS_PERSONALController : GenericoController<TIPOS_PERSONAL, int>
|
||||
{
|
||||
public TIPOS_PERSONALController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TITULACIONESController : GenericoController<TITULACIONES, int>
|
||||
{
|
||||
public TITULACIONESController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetWithIncludes/{id}")]
|
||||
public async Task<IActionResult> GetWithIncludes(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.TITULACIONES
|
||||
.Include(p => p.IDPERSONANavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDPERSONA == id).ToListAsync();
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<PUESTOS>();
|
||||
var entity = context.TITULACIONES
|
||||
.Include(x=> x.IDPERSONANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDTITULACION == id);
|
||||
|
||||
if (entity == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TRIENIOSController : GenericoController<TRIENIOS, int>
|
||||
{
|
||||
public TRIENIOSController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("GetWithIncludes/{id}")]
|
||||
public async Task<IActionResult> GetWithIncludes(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
// Consulta con Includes necesarios
|
||||
var entity = await context.TRIENIOS
|
||||
.Include(p => p.IDGRUPONavigation)
|
||||
.AsNoTracking()
|
||||
.Where(p => p.IDPERSONAL == id).ToListAsync();
|
||||
|
||||
// Verifica si la entidad no se encontró
|
||||
if (entity == null)
|
||||
return NotFound($"El puesto con ID {id} no fue encontrado.");
|
||||
|
||||
// Devuelve la entidad con las relaciones cargadas
|
||||
return Ok(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UNIDADADMINISTRATIVAController : GenericoController<UNIDADADMINISTRATIVA, int>
|
||||
{
|
||||
public UNIDADADMINISTRATIVAController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using bdAntifraude.db;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class VEHICULOSController : GenericoController<VEHICULOS, int>
|
||||
{
|
||||
public VEHICULOSController()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using Serialize.Linq.Serializers;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class VIDA_ADMINISTRATIVAController : GenericoController<VIDA_ADMINISTRATIVA, int>
|
||||
{
|
||||
public VIDA_ADMINISTRATIVAController() : base() { }
|
||||
|
||||
[HttpGet]
|
||||
public override async Task<IActionResult> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var entities = await context.VIDA_ADMINISTRATIVA
|
||||
.Include(v => v.IDMOTIVONavigation)
|
||||
.ThenInclude(m => m.IDTIPOAPTOSNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.ThenInclude(x => x.IDRPTDESNavigation)
|
||||
.ThenInclude(y => y.IDDEPARTAMENTONavigation)
|
||||
.Include(v => v.IDTRAMOCARRERAHORIZONTALNavigation)
|
||||
.Include(v => v.IDTIPOPERSONALNavigation)
|
||||
.Include(v => v.NIVEL_OLDNavigation)
|
||||
.Include(v => v.NIVELCNavigation)
|
||||
.Include(v => v.GRUPOTNavigation)
|
||||
.Include(v => v.OCUPACION_OLDNavigation)
|
||||
.Include(v => v.IDPERSONALNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.ThenInclude(n => n.IDRPTDESNavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("{id}")]
|
||||
public override IActionResult GetById(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
//var dbSet = context.Set<VIDA_ADMINISTRATIVA>();
|
||||
var entities = context.VIDA_ADMINISTRATIVA
|
||||
.Include(v => v.IDMOTIVONavigation)
|
||||
.ThenInclude(m => m.IDTIPOAPTOSNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.Include(v => v.IDPERSONALNavigation)
|
||||
.ThenInclude(x => x.IDGRUPOFUNCIONARIONavigation)
|
||||
.Include(v => v.IDTRAMOCARRERAHORIZONTALNavigation)
|
||||
.Include(v => v.IDTIPOPERSONALNavigation)
|
||||
.Include(v => v.NIVEL_OLDNavigation)
|
||||
.Include(v => v.GRUPOTNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.ThenInclude(s => s.IDRPTDESNavigation)
|
||||
.ThenInclude(y => y.IDDEPARTAMENTONavigation)
|
||||
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(v => v.IDVIDA == id);
|
||||
|
||||
|
||||
|
||||
if (entities == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpPost("filtrar")] // Cambié a POST ya que estás usando [FromBody]
|
||||
public override async Task<IActionResult> Filtrar([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<VIDA_ADMINISTRATIVA, bool>>;
|
||||
if (deserializedExpression == null)
|
||||
{
|
||||
return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
}
|
||||
var entities = await context.VIDA_ADMINISTRATIVA.Where(deserializedExpression)
|
||||
.Include(v => v.IDMOTIVONavigation)
|
||||
.ThenInclude(m => m.IDTIPOAPTOSNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.Include(v => v.IDTRAMOCARRERAHORIZONTALNavigation)
|
||||
.Include(v => v.IDTIPOPERSONALNavigation)
|
||||
.Include(v => v.NIVEL_OLDNavigation)
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(v => v.NIVELCNavigation)
|
||||
.Include(v => v.GRUPOTNavigation)
|
||||
.Include(v => v.OCUPACION_OLDNavigation)
|
||||
.Include(v => v.IDPERSONALNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.ThenInclude(n => n.IDRPTDESNavigation)
|
||||
.ThenInclude(gr => gr.GRUPO1Navigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.ThenInclude(n => n.IDRPTDESNavigation)
|
||||
.ThenInclude(x => x.IDDEPARTAMENTONavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("puestospersona/{idPersona}")]
|
||||
public async Task<IActionResult> PuestosPersona(int idPersona)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var entities = bdAntifraude.Utilidades.ObtienePuestoPersona(context,idPersona);
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet("vidaspersona/{idPersona}")]
|
||||
public async Task<IActionResult> VidasPersona(int idPersona)
|
||||
{
|
||||
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<VIDA_ADMINISTRATIVA, bool>>;
|
||||
//if (deserializedExpression == null)
|
||||
//{
|
||||
// return BadRequest("La expresión deserializada es nula o incorrecta.");
|
||||
//}
|
||||
var entities = await context.VIDA_ADMINISTRATIVA.Where(x => x.IDPERSONAL == idPersona)
|
||||
.Include(v => v.IDMOTIVONavigation)
|
||||
.ThenInclude(m => m.IDTIPOAPTOSNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.Include(v => v.IDTRAMOCARRERAHORIZONTALNavigation)
|
||||
.Include(v => v.IDTIPOPERSONALNavigation)
|
||||
.Include(v => v.NIVEL_OLDNavigation)
|
||||
//.Include(v => v.IDSERVICIOADSCRITONavigation)
|
||||
//.Include(v => v.IDUNIDADADMINISTRATIVANavigation)
|
||||
.Include(v => v.NIVELCNavigation)
|
||||
.Include(v => v.GRUPOTNavigation)
|
||||
.Include(v => v.LINEASVIDAADMINISTRATIVA)
|
||||
.Include(v => v.OCUPACION_OLDNavigation)
|
||||
.Include(v => v.IDPERSONALNavigation)
|
||||
.Include(v => v.IDPUESTONavigation)
|
||||
.ThenInclude(n => n.IDRPTDESNavigation)
|
||||
.ThenInclude(x => x.IDDEPARTAMENTONavigation)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
// Verificar si el resultado es vacío
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
Console.WriteLine("La consulta no devolvió resultados.");
|
||||
}
|
||||
|
||||
return Ok(entities);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using bdAntifraude.dbcontext;
|
||||
using SwaggerAntifraude.Controllers;
|
||||
using bdAntifraude.vistas;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.AspNetCore.Authorization; // Asegúrate de importar el namespace correcto para VePersonas
|
||||
|
||||
namespace SwaggerAntifraude.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class VePersonasController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Obtiene una lista de VePersonas con un filtro opcional de activos.
|
||||
/// </summary>
|
||||
/// <param name="activos">Indica si solo se deben devolver las personas activas.</param>
|
||||
/// <returns>Lista de VePersonas.</returns>
|
||||
[Authorize(Policy = "LecturaPolicy")]
|
||||
[HttpGet]
|
||||
public IActionResult ObtenerVistaPersonas(bool activos = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: true))
|
||||
{
|
||||
// Llamar al método ObtenerVistaPersonas
|
||||
var personas = VePersonas.ObtenerVistaPersonas(context, activos);
|
||||
|
||||
|
||||
|
||||
return Ok(personas);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Error interno del servidor: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Antifraude.Net/SwaggerAntifraude/DTOs/LoginDto.cs
Normal file
9
Antifraude.Net/SwaggerAntifraude/DTOs/LoginDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace SwaggerAntifraude.DTOs
|
||||
{
|
||||
public class LoginDto
|
||||
{
|
||||
public string NombreUsuario { get; set; }
|
||||
public string Contraseña { get; set; }
|
||||
public string Origen { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SwaggerAntifraude.Middlewares
|
||||
{
|
||||
public class ExceptionMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<ExceptionMiddleware> _logger;
|
||||
|
||||
public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Ocurrió un error: {ex}");
|
||||
|
||||
switch (ex)
|
||||
{
|
||||
case DbUpdateException dbEx:
|
||||
await HandleExceptionAsync(context, "Error al actualizar la base de datos.", HttpStatusCode.BadRequest);
|
||||
break;
|
||||
case KeyNotFoundException _:
|
||||
await HandleExceptionAsync(context, "Recurso no encontrado.", HttpStatusCode.NotFound);
|
||||
break;
|
||||
default:
|
||||
await HandleExceptionAsync(context, "Ocurrió un error inesperado. Por favor, inténtalo de nuevo más tarde.", HttpStatusCode.InternalServerError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Task HandleExceptionAsync(HttpContext context, string message, HttpStatusCode statusCode)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.StatusCode = (int)statusCode;
|
||||
|
||||
var response = new { message };
|
||||
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
|
||||
return context.Response.WriteAsync(JsonSerializer.Serialize(response, options));
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Antifraude.Net/SwaggerAntifraude/Models/Personal.cs
Normal file
18
Antifraude.Net/SwaggerAntifraude/Models/Personal.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace SwaggerAntifraude.Models
|
||||
{
|
||||
public class Personal
|
||||
{
|
||||
public string Nombre { get; set; }
|
||||
public string Dni { get; set; }
|
||||
public int idPersona { get; set; }
|
||||
public string Departamento { get; set; }
|
||||
public string Roll { get; set; }
|
||||
public int NumeroInciPorAceptar { get; set; }
|
||||
public int NumeroInciBorrador { get; set; }
|
||||
public DateTime FeIniInciPorAceptar { get; set; }
|
||||
public DateTime FeFinInciPorAceptar { get; set; }
|
||||
public DateTime FeIniInciBorrador { get; set; }
|
||||
public DateTime FeFinInciBorrador { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
|
||||
|
||||
namespace SwaggerAntifraude.Models
|
||||
{
|
||||
public class ResultadoIdentificacion
|
||||
{
|
||||
public int resultado { get; set; }
|
||||
public List<Personal> Personas { get; set; }
|
||||
public DateTime FeIniInciPorAceptar { get; set; }
|
||||
public DateTime FeFinInciPorAceptar { get; set; }
|
||||
public string errores { get; set; }
|
||||
}
|
||||
}
|
||||
170
Antifraude.Net/SwaggerAntifraude/Program.cs
Normal file
170
Antifraude.Net/SwaggerAntifraude/Program.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using bdAntifraude.dbcontext;
|
||||
using SwaggerAntifraude.Middlewares;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// 1. Configuraci<63>n de Servicios
|
||||
|
||||
// a. Configurar servicios de controladores
|
||||
builder.Services.AddControllers()
|
||||
.ConfigureApiBehaviorOptions(options =>
|
||||
{
|
||||
options.SuppressModelStateInvalidFilter = true; // Desactiva la validaci<63>n autom<6F>tica del estado del modelo
|
||||
})
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||
});
|
||||
|
||||
// b. Configuraci<63>n de JWT
|
||||
var jwtSettings = builder.Configuration.GetSection("Jwt");
|
||||
var keyString = jwtSettings["Key"];
|
||||
if (string.IsNullOrEmpty(keyString))
|
||||
{
|
||||
throw new ArgumentNullException("JWT Key is not configured.");
|
||||
}
|
||||
var key = Encoding.UTF8.GetBytes(keyString);
|
||||
|
||||
if (!double.TryParse(jwtSettings["ExpiresInMinutes"], out double expiresInMinutes))
|
||||
{
|
||||
expiresInMinutes = 60; // Valor por defecto
|
||||
}
|
||||
|
||||
builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = jwtSettings["Issuer"],
|
||||
ValidAudience = jwtSettings["Audience"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key)
|
||||
};
|
||||
});
|
||||
|
||||
builder.WebHost.ConfigureKestrel(options =>
|
||||
{
|
||||
options.ConfigureHttpsDefaults(httpsOptions =>
|
||||
{
|
||||
httpsOptions.ClientCertificateMode =
|
||||
Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode.AllowCertificate;
|
||||
|
||||
// (Opcional, en pruebas)
|
||||
httpsOptions.AllowAnyClientCertificate();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// c. Definir Pol<6F>ticas de Autorizaci<63>n
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("SupervisorPolicy", policy => policy.RequireRole("Supervisor"));
|
||||
options.AddPolicy("LecturaPolicy", policy => policy.RequireRole("Lectura", "Supervisor"));
|
||||
});
|
||||
|
||||
// d. Configurar Swagger con soporte para JWT
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Swagger OAAF API", Version = "v1" });
|
||||
|
||||
// Definir el esquema de seguridad JWT
|
||||
var securityScheme = new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "Authorization",
|
||||
Description = "Ingrese 'Bearer' seguido de su token en el campo de texto.\n\nEjemplo: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6...'",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer",
|
||||
BearerFormat = "JWT"
|
||||
};
|
||||
|
||||
c.AddSecurityDefinition("Bearer", securityScheme);
|
||||
|
||||
|
||||
var securityRequirement = new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
new string[] {}
|
||||
}
|
||||
};
|
||||
|
||||
c.AddSecurityRequirement(securityRequirement);
|
||||
|
||||
// Incluir comentarios XML para Swagger
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
if (File.Exists(xmlPath))
|
||||
{
|
||||
c.IncludeXmlComments(xmlPath);
|
||||
}
|
||||
});
|
||||
|
||||
// Inicializar las cadenas de conexi<78>n
|
||||
var connectionStrings = builder.Configuration.GetSection("ConnectionStrings");
|
||||
var writeConnectionString = connectionStrings["WriteConnection"];
|
||||
var readOnlyConnectionString = connectionStrings["ReadOnlyConnection"];
|
||||
|
||||
if (string.IsNullOrEmpty(writeConnectionString) || string.IsNullOrEmpty(readOnlyConnectionString))
|
||||
{
|
||||
throw new ArgumentNullException("Las cadenas de conexi<78>n no est<73>n configuradas correctamente.");
|
||||
}
|
||||
|
||||
tsGestionAntifraude.EstableceCBD(writeConnectionString, readOnlyConnectionString);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// 2. Configuraci<63>n del Pipeline HTTP
|
||||
|
||||
// a. Middleware de Excepciones
|
||||
app.UseMiddleware<ExceptionMiddleware>();
|
||||
|
||||
// b. Habilitar Swagger solo en Desarrollo
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "SwaggerCamcue API V1");
|
||||
c.RoutePrefix = string.Empty; // Swagger en la ra<72>z
|
||||
});
|
||||
}
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
// c. Configurar CORS (Opcional)
|
||||
app.UseCors("AllowSpecificOrigin");
|
||||
|
||||
// d. Autenticaci<63>n y Autorizaci<63>n
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// e. Mapear Controladores
|
||||
app.MapControllers();
|
||||
|
||||
// f. Ejecutar la Aplicaci<63>n
|
||||
app.Run();
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:12137",
|
||||
"sslPort": 44362
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5117",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7135;http://localhost:5117",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Renci.SshNet;
|
||||
using bdAntifraude.dbcontext;
|
||||
using SwaggerAntifraude.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using bdAntifraude.clases;
|
||||
|
||||
namespace SwaggerAntifraude.Servicios
|
||||
{
|
||||
|
||||
public class ServicioAlmacenamiento
|
||||
{
|
||||
private static IConfiguration Conf { get; set; }
|
||||
public ResultadoAlmacenaFicheroAtransmitir DevolverResultadoAlmacenaFicheroAtransmitir(int idRegistro, string tabla, string ficheroBase64)
|
||||
{
|
||||
var resultado = new ResultadoAlmacenaFicheroAtransmitir();
|
||||
|
||||
try
|
||||
{
|
||||
// Convertir el archivo Base64 a un flujo
|
||||
var stream = new MemoryStream(Convert.FromBase64String(ficheroBase64));
|
||||
|
||||
// Obtener el nombre de la base de datos utilizando el contexto
|
||||
string baseDeDatos;
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
{
|
||||
baseDeDatos = context.Database.GetDbConnection().Database;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(baseDeDatos))
|
||||
{
|
||||
Conf = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
baseDeDatos = Conf.GetSection("BaseDatos").Value; ;
|
||||
}
|
||||
|
||||
// Conectar al servidor SFTP utilizando el contexto
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
using (var clienteSftp = ConectarServidorSftp(context))
|
||||
{
|
||||
clienteSftp.Connect();
|
||||
|
||||
// Generar la ruta base
|
||||
string ruta = $"{baseDeDatos.ToLower()}/registrodepersonal";
|
||||
|
||||
switch (tabla.ToUpper())
|
||||
{
|
||||
case "LINEAVIDAADMINISTRATIVA":
|
||||
ruta += "/lineavidaadministrativa/";
|
||||
break;
|
||||
case "FORMACION":
|
||||
ruta += "/formacion/";
|
||||
break;
|
||||
case "TITULACION":
|
||||
ruta += "/titulacion/";
|
||||
break;
|
||||
case "DOCENCIA":
|
||||
ruta += "/docencia/";
|
||||
break;
|
||||
case "INCIDENCIA":
|
||||
ruta = $"{baseDeDatos.ToLower()}/control_horario/";
|
||||
break;
|
||||
default:
|
||||
resultado.Resultado = 1;
|
||||
resultado.Mensaje = "Tabla no contemplada entre las posibles para tener ficheros";
|
||||
return resultado;
|
||||
}
|
||||
|
||||
// Subir el archivo al servidor SFTP
|
||||
ruta += $"{idRegistro}.pdf";
|
||||
clienteSftp.UploadFile(stream, ruta);
|
||||
clienteSftp.Disconnect();
|
||||
|
||||
resultado.Resultado = 0;
|
||||
resultado.Mensaje = "Fichero almacenado";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultado.Resultado = 1;
|
||||
resultado.Mensaje = $"ERROR de generación: {ex.Message}";
|
||||
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
resultado.Mensaje += $" {ex.InnerException.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
return resultado;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ResultadoObtenFicheroAtransmitir DevolverObtenFicheroAtransmitir(int idRegistro, string tabla, string nif)
|
||||
{
|
||||
var resultado = new ResultadoObtenFicheroAtransmitir();
|
||||
|
||||
try
|
||||
{
|
||||
// Obtener el nombre de la base de datos utilizando el contexto
|
||||
string baseDeDatos;
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
{
|
||||
baseDeDatos = context.Database.GetDbConnection().Database;
|
||||
}
|
||||
|
||||
Conf = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
baseDeDatos = Conf.GetSection("BaseDatos").Value; ;
|
||||
|
||||
//if (string.IsNullOrEmpty(baseDeDatos))
|
||||
//{
|
||||
// baseDeDatos = "preproduccion";
|
||||
//}
|
||||
|
||||
// Generar la ruta base
|
||||
string ruta = $"{baseDeDatos.ToLower()}/registrodepersonal";
|
||||
|
||||
switch (tabla.ToUpper())
|
||||
{
|
||||
case "LINEAVIDAADMINISTRATIVA":
|
||||
ruta += "/lineavidaadministrativa/";
|
||||
break;
|
||||
case "FORMACION":
|
||||
ruta += "/formacion/";
|
||||
break;
|
||||
case "TITULACION":
|
||||
ruta += "/titulacion/";
|
||||
break;
|
||||
case "DOCENCIA":
|
||||
ruta += "/docencia/";
|
||||
break;
|
||||
case "INCIDENCIA":
|
||||
ruta = $"{baseDeDatos.ToLower()}/control_horario/";
|
||||
break;
|
||||
case "CSV":
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
{
|
||||
//ruta += context.VALIDACIONDOCUMENTOS.First(x => x.CSV == nif).RUTAFICHERO;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
resultado.Resultado = 1;
|
||||
resultado.Mensaje = "Tabla no contemplada entre las posibles para tener ficheros";
|
||||
return resultado;
|
||||
}
|
||||
|
||||
if (tabla.ToUpper() != "CSV")
|
||||
{
|
||||
ruta += $"{idRegistro}.pdf";
|
||||
}
|
||||
|
||||
resultado.Mensaje = $"Ruta: {ruta}";
|
||||
|
||||
// Descargar el archivo desde el servidor SFTP
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true))
|
||||
using (var clienteSftp = ConectarServidorSftp(context))
|
||||
{
|
||||
clienteSftp.Connect();
|
||||
|
||||
using var memoryStream = new MemoryStream();
|
||||
clienteSftp.DownloadFile(ruta, memoryStream);
|
||||
clienteSftp.Disconnect();
|
||||
|
||||
resultado.Pdf = memoryStream.ToArray();
|
||||
}
|
||||
|
||||
resultado.Resultado = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultado.Resultado = 1;
|
||||
resultado.Mensaje = $"ERROR de generación: {ex.Message}";
|
||||
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
resultado.Mensaje += $" {ex.InnerException.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
return resultado;
|
||||
}
|
||||
|
||||
|
||||
private SftpClient ConectarServidorSftp(tsGestionAntifraude context)
|
||||
{
|
||||
var configuraciones = context.ENUMERACIONES
|
||||
.Where(x => x.IDGRUPOENUMERACIONNavigation.GRUPO == "SERVIDORSFTP")
|
||||
.ToList();
|
||||
|
||||
var servidor = configuraciones.First(n => n.CODIGO == "SERVIDORSFTP.SERVIDOR").VALORALFABETICO1;
|
||||
var puerto = int.Parse(configuraciones.First(n => n.CODIGO == "SERVIDORSFTP.PUERTO").VALORALFABETICO1);
|
||||
var usuario = configuraciones.First(n => n.CODIGO == "SERVIDORSFTP.USUARIO").VALORALFABETICO1;
|
||||
var clave = tsUtilidades.crypt.FEncS(
|
||||
configuraciones.First(n => n.CODIGO == "SERVIDORSFTP.CLAVE").VALORALFABETICO1,
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/\\-*",
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/\\-*",
|
||||
-875421649);
|
||||
|
||||
return new SftpClient(servidor, puerto, usuario, clave);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,819 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude.dbcontext;
|
||||
using bdAntifraude.DatRecTri;
|
||||
|
||||
namespace SwaggerAntifraude.Servicios
|
||||
{
|
||||
public class ServicioFormularios
|
||||
{
|
||||
public byte[] GenerarFormulario(
|
||||
string claveFormulario,
|
||||
string idPersona,
|
||||
string Motivo,
|
||||
string texto1,
|
||||
string texto2,
|
||||
string FechaEfecto,
|
||||
string Organo,
|
||||
string FechaEmision,
|
||||
string Extra)
|
||||
{
|
||||
switch (claveFormulario)
|
||||
{
|
||||
case "TomPos":
|
||||
return DevuelveTomaPosesion(idPersona, Motivo, texto1, FechaEfecto, Organo, FechaEmision);
|
||||
case "CumTri":
|
||||
return DevuelveCumplimientoTrienios(idPersona, Motivo, texto1, FechaEfecto, Organo, FechaEmision, "RECTRI");
|
||||
case "SolTri":
|
||||
return DevuelveCumplimientoTrienios(idPersona, Motivo, texto1, FechaEfecto, Organo, FechaEmision, "SOLTRI");
|
||||
case "ComInt":
|
||||
return DevuelveComunicacionInterna(idPersona, texto1, texto2, FechaEmision);
|
||||
case "AcuJub":
|
||||
return DevuelveAcuerdoJubilacion(idPersona, Motivo, texto1, FechaEfecto, Organo, FechaEmision, Extra);
|
||||
case "AcuBaj":
|
||||
return DevuelveAcuerdoBaja(idPersona, Motivo, texto1, FechaEfecto, Organo, FechaEmision);
|
||||
case "AcuCes":
|
||||
return DevuelveAcuerdoCese(idPersona, Motivo, texto1, FechaEfecto, Organo, FechaEmision);
|
||||
case "ConGra":
|
||||
return DevuelveConsolidacionGrado(idPersona, Motivo, texto1, texto2, FechaEfecto, Organo, FechaEmision);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] DevuelveTomaPosesion(
|
||||
string idPersona,
|
||||
string motivo,
|
||||
string texto1,
|
||||
string fechaEfecto,
|
||||
string organo,
|
||||
string fechaEmision)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
PERSONAS per = new PERSONAS();
|
||||
var LisTomPos = new List<bdAntifraude.DatRecTri.RecTri>();
|
||||
var ForTomPos = new bdAntifraude.DatRecTri.RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
ForTomPos.Nif = per.NIF;
|
||||
ForTomPos.Apellidos = per.APELLIDOS;
|
||||
ForTomPos.Nombre = per.NOMBRE;
|
||||
ForTomPos.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForTomPos.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForTomPos.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForTomPos.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForTomPos.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
|
||||
PUESTOS PuestoTrabajo = null;
|
||||
|
||||
var puestosPersona = context.PUESTOS.Where(x => x.IDPERSONAL == per.IDPERSONA);
|
||||
if (puestosPersona.Any())
|
||||
{
|
||||
PuestoTrabajo = puestosPersona
|
||||
.OrderByDescending(x => x.IDRPTNavigation.F_PARLAMENTO.Value)
|
||||
.First();
|
||||
|
||||
ForTomPos.DesPuesTrab = PuestoTrabajo.IDRPTDESNavigation.DENOMINACION;
|
||||
}
|
||||
|
||||
if (per.DEPARTAMENTOACTUAL != null)
|
||||
ForTomPos.Departamento = per.IDDEPARTAMENTONavigation.DESCRIPCION;
|
||||
|
||||
if (PuestoTrabajo != null)
|
||||
{
|
||||
ForTomPos.CuerpoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.CUERPO1Navigation.DESCRIPCION;
|
||||
|
||||
double Especifico = double.Parse(PuestoTrabajo.IDRPTDESNavigation.ESPECIFICO.ToString());
|
||||
ForTomPos.ComEsp = Especifico.ToString("##,##0.00") + "€";
|
||||
|
||||
ForTomPos.GrupoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1;
|
||||
ForTomPos.NivelPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.IDNIVEL_RPTNavigation.NIVEL1;
|
||||
ForTomPos.CarOcu = PuestoTrabajo.IDOCUPACIONNavigation.DESCRIPCION;
|
||||
}
|
||||
|
||||
ForTomPos.MotivoTomaPosesion = motivo;
|
||||
ForTomPos.texto1 = texto1;
|
||||
ForTomPos.FechaEfectoTomaPosesion = fechaEfecto;
|
||||
ForTomPos.OrganoCompetente = organo;
|
||||
ForTomPos.FechaEmision = fechaEmision;
|
||||
}
|
||||
|
||||
LisTomPos.Add(ForTomPos);
|
||||
|
||||
var pl = context.PLANTILLAS.First(x => x.CODIGO == "TOMPOS");
|
||||
var idPlantilla = pl.IDPLANTILLA;
|
||||
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisTomPos).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private byte[] DevuelveCumplimientoTrienios(
|
||||
string idPersona,
|
||||
string motivo,
|
||||
string texto1,
|
||||
string fechaEfecto,
|
||||
string organo,
|
||||
string fechaEmision,
|
||||
string Tipo)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
PERSONAS per=null;
|
||||
var LisCumTri = new List<bdAntifraude.DatRecTri.RecTri>();
|
||||
var ForCumTri = new bdAntifraude.DatRecTri.RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
ForCumTri.Nif = per.NIF;
|
||||
ForCumTri.Apellidos = per.APELLIDOS;
|
||||
ForCumTri.Nombre = per.NOMBRE;
|
||||
ForCumTri.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForCumTri.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForCumTri.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForCumTri.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForCumTri.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
ForCumTri.Localidad = per.NombrePoblacion;
|
||||
ForCumTri.Provincia = per.NombreProvincia;
|
||||
|
||||
PUESTOS PuestoTrabajo = null;
|
||||
var iDSitRptAct = context.ENUMERACIONES.First(x => x.CODIGO == "SITRPTMAESTRO.ACT").IDENUMERACION;
|
||||
|
||||
var puestosActivos = context.PUESTOS
|
||||
.Where(x => x.IDPERSONAL == per.IDPERSONA && x.IDRPTNavigation.IDSITUACION == iDSitRptAct);
|
||||
|
||||
if (puestosActivos.Any())
|
||||
{
|
||||
PuestoTrabajo = puestosActivos.First();
|
||||
ForCumTri.DesPuesTrab = PuestoTrabajo.IDRPTDESNavigation.DENOMINACION;
|
||||
}
|
||||
|
||||
if (per.FECHACUMPLIMIENTOPROXTRIENIO.HasValue)
|
||||
{
|
||||
//Truncamos la fecha a los primeros 10 caracteres
|
||||
var fechaProx = per.FECHACUMPLIMIENTOPROXTRIENIO.Value;
|
||||
ForCumTri.FecVenTri = fechaProx.ToString("yyyy-MM-dd").Substring(0, 10);
|
||||
|
||||
if (fechaProx.Day == 1)
|
||||
{
|
||||
ForCumTri.FechaEfeEco = fechaProx.ToString("yyyy-MM-dd").Substring(0, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
var Fechaefe = fechaProx.AddMonths(1);
|
||||
var primerDiaMesSiguiente = new DateTime(Fechaefe.Year, Fechaefe.Month, 1);
|
||||
ForCumTri.FechaEfeEco = primerDiaMesSiguiente.ToString("yyyy-MM-dd").Substring(0, 10);
|
||||
}
|
||||
|
||||
ForCumTri.FecCumProTri = fechaProx.AddYears(3).ToString("yyyy-MM-dd").Substring(0, 10);
|
||||
}
|
||||
|
||||
//Calcular trienios
|
||||
if (per.TRIENIOS.Any())
|
||||
{
|
||||
foreach (var trienio in per.TRIENIOS.ToList())
|
||||
{
|
||||
var grupoTrim = trienio.GRUPO.Trim();
|
||||
switch (grupoTrim)
|
||||
{
|
||||
case "A1":
|
||||
case "I":
|
||||
ForCumTri.TriA1 = trienio.TC;
|
||||
if (per.GRUPOFUNCIONARIODESCRIPCION == "A1")
|
||||
ForCumTri.TriA1 = (int)(trienio.TC + trienio.TOA + 1);
|
||||
break;
|
||||
case "A2":
|
||||
case "II":
|
||||
ForCumTri.TriA2 = trienio.TC;
|
||||
if (per.GRUPOFUNCIONARIODESCRIPCION == "A2")
|
||||
ForCumTri.TriA2 = trienio.TC + trienio.TOA + 1;
|
||||
break;
|
||||
case "C1":
|
||||
case "III":
|
||||
ForCumTri.TriC1 = trienio.TC;
|
||||
if (per.GRUPOFUNCIONARIODESCRIPCION == "C1")
|
||||
ForCumTri.TriC1 = trienio.TC + trienio.TOA + 1;
|
||||
break;
|
||||
case "C2":
|
||||
case "IV":
|
||||
ForCumTri.TriC2 = trienio.TC;
|
||||
if (per.GRUPOFUNCIONARIODESCRIPCION == "C2")
|
||||
ForCumTri.TriC2 = trienio.TC + trienio.TOA + 1;
|
||||
break;
|
||||
case "E":
|
||||
case "V":
|
||||
ForCumTri.TriE = trienio.TC;
|
||||
if (per.GRUPOFUNCIONARIODESCRIPCION == "E")
|
||||
ForCumTri.TriE = trienio.TC + trienio.TOA + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//No hay trienios, se asigna 1 según el grupo
|
||||
if (!string.IsNullOrWhiteSpace(per.GRUPOFUNCIONARIODESCRIPCION))
|
||||
{
|
||||
switch (per.GRUPOFUNCIONARIODESCRIPCION.Trim())
|
||||
{
|
||||
case "A1":
|
||||
ForCumTri.TriA1 = 1;
|
||||
break;
|
||||
case "A2":
|
||||
ForCumTri.TriA2 = 1;
|
||||
break;
|
||||
case "C1":
|
||||
ForCumTri.TriC1 = 1;
|
||||
break;
|
||||
case "C2":
|
||||
ForCumTri.TriC2 = 1;
|
||||
break;
|
||||
case "E":
|
||||
ForCumTri.TriE = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (PuestoTrabajo != null)
|
||||
{
|
||||
//Si no hay grupo en persona, se toma del puesto de trabajo
|
||||
var grupoPT = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1.Trim();
|
||||
switch (grupoPT)
|
||||
{
|
||||
case "A1":
|
||||
ForCumTri.TriA1 = 1;
|
||||
break;
|
||||
case "A2":
|
||||
ForCumTri.TriA2 = 1;
|
||||
break;
|
||||
case "C1":
|
||||
ForCumTri.TriC1 = 1;
|
||||
break;
|
||||
case "C2":
|
||||
ForCumTri.TriC2 = 1;
|
||||
break;
|
||||
case "E":
|
||||
ForCumTri.TriE = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Departamento y otros datos del puesto
|
||||
if (PuestoTrabajo != null)
|
||||
{
|
||||
ForCumTri.Departamento = PuestoTrabajo.IDRPTDESNavigation.DEPARTAMENTO;
|
||||
ForCumTri.CuerpoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.CUERPO1Navigation.DESCRIPCION;
|
||||
|
||||
double Especifico = double.Parse(PuestoTrabajo.IDRPTDESNavigation.ESPECIFICO.ToString());
|
||||
ForCumTri.ComEsp = Especifico.ToString("##,##0.00") + "€";
|
||||
|
||||
ForCumTri.GrupoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1;
|
||||
ForCumTri.NivelPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.IDNIVEL_RPTNavigation.NIVEL1;
|
||||
|
||||
if (per.NIVEL != null)
|
||||
ForCumTri.Nivel = per.IDNIVELRPTNavigation.NIVEL1;
|
||||
|
||||
ForCumTri.CarOcu = PuestoTrabajo.IDOCUPACIONNavigation.DESCRIPCION;
|
||||
}
|
||||
|
||||
ForCumTri.MotivoTomaPosesion = motivo;
|
||||
ForCumTri.texto1 = texto1;
|
||||
|
||||
if (!string.IsNullOrEmpty(fechaEfecto) && fechaEfecto.Length >= 10)
|
||||
ForCumTri.FechaEfectoTomaPosesion = fechaEfecto.Substring(0, 10);
|
||||
|
||||
ForCumTri.OrganoCompetente = organo;
|
||||
ForCumTri.FechaEmision = fechaEmision;
|
||||
|
||||
ForCumTri.TolTri = per.TRIENIOS.Sum(x => x.TC) + per.TRIENIOS.Sum(x => x.TOA);
|
||||
ForCumTri.texto1 = (ForCumTri.TolTri + 1).ToString();
|
||||
|
||||
if (per.FECHACUMPLIMIENTOPROXTRIENIO.HasValue)
|
||||
{
|
||||
var fechaProx = per.FECHACUMPLIMIENTOPROXTRIENIO.Value;
|
||||
ForCumTri.texto2 = fechaProx.Day.ToString().PadLeft(2, '0') + " de " +
|
||||
tsUtilidades.Extensiones.DateTimeExtensions.MesCastellano(fechaProx) + " de " +
|
||||
fechaProx.Year.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
LisCumTri.Add(ForCumTri);
|
||||
|
||||
if (per != null && per.IDADSCRIPCIONRPTNavigation.DESCRIPCION == "LABORAL")
|
||||
{
|
||||
switch (ForCumTri.Grupo)
|
||||
{
|
||||
case "A1":
|
||||
ForCumTri.Grupo = "I";
|
||||
break;
|
||||
case "A2":
|
||||
ForCumTri.Grupo = "II";
|
||||
break;
|
||||
case "C1":
|
||||
ForCumTri.Grupo = "III";
|
||||
break;
|
||||
case "C2":
|
||||
ForCumTri.Grupo = "IV";
|
||||
break;
|
||||
case "E":
|
||||
ForCumTri.Grupo = "V";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PLANTILLAS pl;
|
||||
|
||||
if (Tipo == "RECTRI")
|
||||
{
|
||||
pl = context.PLANTILLAS.First(x => x.CODIGO == "RECTRI");
|
||||
if (per.IDADSCRIPCIONRPTNavigation.DESCRIPCION == "LABORAL")
|
||||
pl = context.PLANTILLAS.First(x => x.CODIGO == "RECTRIL");
|
||||
}
|
||||
else
|
||||
{
|
||||
pl = context.PLANTILLAS.First(x => x.CODIGO == "RECTRI4");
|
||||
if (per.IDADSCRIPCIONRPTNavigation.DESCRIPCION == "LABORAL")
|
||||
pl = context.PLANTILLAS.First(x => x.CODIGO == "RECTRI4L");
|
||||
}
|
||||
|
||||
var idPlantilla = pl.IDPLANTILLA;
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisCumTri).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] DevuelveComunicacionInterna(
|
||||
string idPersona,
|
||||
string texto1,
|
||||
string texto2,
|
||||
string fechaEmision)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
PERSONAS per;
|
||||
var LisCumTri = new List<bdAntifraude.DatRecTri.RecTri>();
|
||||
var ForCumTri = new bdAntifraude.DatRecTri.RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
ForCumTri.Nif = per.NIF;
|
||||
ForCumTri.Apellidos = per.APELLIDOS;
|
||||
ForCumTri.Nombre = per.NOMBRE;
|
||||
ForCumTri.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForCumTri.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForCumTri.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForCumTri.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForCumTri.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
ForCumTri.Localidad = per.NombrePoblacion;
|
||||
ForCumTri.Provincia = per.NombreProvincia;
|
||||
|
||||
if (per.IDDEPARTAMENTO != null)
|
||||
ForCumTri.Departamento = per.IDDEPARTAMENTONavigation.DESCRIPCION;
|
||||
|
||||
ForCumTri.FechaEmision = fechaEmision;
|
||||
ForCumTri.texto1 = texto1;
|
||||
ForCumTri.texto2 = texto2;
|
||||
}
|
||||
|
||||
LisCumTri.Add(ForCumTri);
|
||||
|
||||
var pl = context.PLANTILLAS.First(x => x.CODIGO == "COMUNI");
|
||||
var idPlantilla = pl.IDPLANTILLA;
|
||||
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisCumTri).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] DevuelveAcuerdoJubilacion(
|
||||
string idPersona,
|
||||
string motivo,
|
||||
string texto1,
|
||||
string fechaEfecto,
|
||||
string organo,
|
||||
string fechaEmision,
|
||||
string fechaEfe)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
var LisAcuJub = new List<RecTri>();
|
||||
var ForAcuJub = new RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
var per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
int Años = 0;
|
||||
if (per.TRIENIOS.Any())
|
||||
{
|
||||
Años = (int)per.TRIENIOS.Sum(x => x.TC + x.TOA) * 3;
|
||||
}
|
||||
|
||||
var Fechafin = tsUtilidades.Extensiones.DateTimeExtensions.FechaHoraStringADate(fechaEfe);
|
||||
|
||||
if (per.FECHACUMPLIMIENTOPROXTRIENIO.HasValue && Fechafin.HasValue)
|
||||
{
|
||||
var TiemSer = bdAntifraude.Utilidades.AnosMesesDias(per.FECHACUMPLIMIENTOPROXTRIENIO.Value.AddYears(-3), Fechafin.Value);
|
||||
|
||||
if (TiemSer != null)
|
||||
{
|
||||
TiemSer.Anos += Años;
|
||||
|
||||
//Construcción del texto1 según años, meses, días
|
||||
string tiempo = "";
|
||||
if (TiemSer.Anos == 1) tiempo += TiemSer.Anos.ToString() + " AÑO ";
|
||||
else if (TiemSer.Anos > 1) tiempo += TiemSer.Anos.ToString() + " AÑOS ";
|
||||
|
||||
if (TiemSer.Meses == 1) tiempo += TiemSer.Meses.ToString() + " MES ";
|
||||
else if (TiemSer.Meses > 1) tiempo += TiemSer.Meses.ToString() + " MESES ";
|
||||
|
||||
if (TiemSer.Dias == 1) tiempo += TiemSer.Dias.ToString() + " DIA ";
|
||||
else if (TiemSer.Dias > 1) tiempo += TiemSer.Dias.ToString() + " DIAS ";
|
||||
|
||||
ForAcuJub.texto1 = tiempo.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
ForAcuJub.Nif = per.NIF;
|
||||
ForAcuJub.Apellidos = per.APELLIDOS;
|
||||
ForAcuJub.Nombre = per.NOMBRE;
|
||||
ForAcuJub.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForAcuJub.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForAcuJub.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForAcuJub.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForAcuJub.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
|
||||
var puestosPersona = context.PUESTOS.Where(x => x.IDPERSONAL == per.IDPERSONA);
|
||||
PUESTOS PuestoTrabajo = null;
|
||||
|
||||
if (puestosPersona.Any())
|
||||
{
|
||||
PuestoTrabajo = puestosPersona
|
||||
.OrderByDescending(x => x.IDRPTNavigation.F_PARLAMENTO.Value)
|
||||
.First();
|
||||
ForAcuJub.DesPuesTrab = PuestoTrabajo.IDRPTDESNavigation.DENOMINACION;
|
||||
}
|
||||
|
||||
if (per.IDDEPARTAMENTO != null)
|
||||
ForAcuJub.Departamento = per.IDDEPARTAMENTONavigation.DESCRIPCION;
|
||||
|
||||
if (PuestoTrabajo != null)
|
||||
{
|
||||
ForAcuJub.CuerpoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.CUERPO1Navigation.DESCRIPCION;
|
||||
|
||||
double Especifico = double.Parse(PuestoTrabajo.IDRPTDESNavigation.ESPECIFICO.ToString());
|
||||
ForAcuJub.ComEsp = Especifico.ToString("##,##0.00") + "€";
|
||||
|
||||
ForAcuJub.GrupoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1;
|
||||
ForAcuJub.NivelPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.IDNIVEL_RPTNavigation.NIVEL1;
|
||||
ForAcuJub.CarOcu = PuestoTrabajo.IDOCUPACIONNavigation.DESCRIPCION;
|
||||
}
|
||||
|
||||
ForAcuJub.MotivoTomaPosesion = motivo;
|
||||
ForAcuJub.texto3 = motivo;
|
||||
|
||||
if (per.FECHANACIMIENTO.HasValue)
|
||||
{
|
||||
var fechaNac = per.FECHANACIMIENTO.Value;
|
||||
string dia = fechaNac.Day.ToString().PadLeft(2, '0');
|
||||
string mes = tsUtilidades.Extensiones.DateTimeExtensions.MesCastellano(fechaNac);
|
||||
string anio = fechaNac.Year.ToString();
|
||||
ForAcuJub.FecVenTri = $"{dia} de {mes} de {anio}";
|
||||
}
|
||||
|
||||
ForAcuJub.FechaEfeEco = fechaEfecto;
|
||||
ForAcuJub.OrganoCompetente = organo;
|
||||
}
|
||||
|
||||
LisAcuJub.Add(ForAcuJub);
|
||||
|
||||
var pl = context.PLANTILLAS.First(x => x.CODIGO == "ACUJUBI");
|
||||
var idPlantilla = pl.IDPLANTILLA;
|
||||
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisAcuJub).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private byte[] DevuelveAcuerdoBaja(
|
||||
string idPersona,
|
||||
string motivo,
|
||||
string texto1,
|
||||
string fechaEfecto,
|
||||
string organo,
|
||||
string fechaEmision)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
PERSONAS per;
|
||||
var LisAcuJub = new List<RecTri>();
|
||||
var ForAcuJub = new RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
ForAcuJub.Nif = per.NIF;
|
||||
ForAcuJub.Apellidos = per.APELLIDOS;
|
||||
ForAcuJub.Nombre = per.NOMBRE;
|
||||
ForAcuJub.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForAcuJub.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForAcuJub.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForAcuJub.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForAcuJub.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
|
||||
PUESTOS PuestoTrabajo = null;
|
||||
var puestosPersona = context.PUESTOS.Where(x => x.IDPERSONAL == per.IDPERSONA);
|
||||
if (puestosPersona.Any())
|
||||
{
|
||||
PuestoTrabajo = puestosPersona
|
||||
.OrderByDescending(x => x.IDRPTNavigation.F_PARLAMENTO.Value)
|
||||
.First();
|
||||
ForAcuJub.DesPuesTrab = PuestoTrabajo.IDRPTDESNavigation.DENOMINACION;
|
||||
|
||||
if (per.IDDEPARTAMENTO != null)
|
||||
ForAcuJub.Departamento = per.IDDEPARTAMENTONavigation.DESCRIPCION;
|
||||
|
||||
ForAcuJub.CuerpoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.CUERPO1Navigation.DESCRIPCION;
|
||||
|
||||
double Especifico = double.Parse(PuestoTrabajo.IDRPTDESNavigation.ESPECIFICO.ToString());
|
||||
ForAcuJub.ComEsp = Especifico.ToString("##,##0.00") + "€";
|
||||
|
||||
ForAcuJub.GrupoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1;
|
||||
ForAcuJub.NivelPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.IDNIVEL_RPTNavigation.NIVEL1;
|
||||
ForAcuJub.CarOcu = PuestoTrabajo.IDOCUPACIONNavigation.DESCRIPCION;
|
||||
}
|
||||
|
||||
ForAcuJub.MotivoTomaPosesion = motivo;
|
||||
ForAcuJub.texto1 = texto1;
|
||||
ForAcuJub.FechaEfectoTomaPosesion = fechaEfecto;
|
||||
ForAcuJub.FechaEfeEco = fechaEfecto;
|
||||
ForAcuJub.OrganoCompetente = organo;
|
||||
ForAcuJub.FecVenTri = fechaEmision;
|
||||
}
|
||||
|
||||
LisAcuJub.Add(ForAcuJub);
|
||||
|
||||
var pl = context.PLANTILLAS.First(x => x.CODIGO == "ACUBAJA");
|
||||
var idPlantilla = pl.IDPLANTILLA;
|
||||
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisAcuJub).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] DevuelveAcuerdoCese(
|
||||
string idPersona,
|
||||
string motivo,
|
||||
string texto1,
|
||||
string fechaEfecto,
|
||||
string organo,
|
||||
string fechaEmision)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
PERSONAS per;
|
||||
var LisAcuJub = new List<RecTri>();
|
||||
var ForAcuJub = new RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
ForAcuJub.Nif = per.NIF;
|
||||
ForAcuJub.Apellidos = per.APELLIDOS;
|
||||
ForAcuJub.Nombre = per.NOMBRE;
|
||||
ForAcuJub.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForAcuJub.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForAcuJub.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForAcuJub.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForAcuJub.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
|
||||
PUESTOS PuestoTrabajo = null;
|
||||
var puestosPersona = context.PUESTOS.Where(x => x.IDPERSONAL == per.IDPERSONA);
|
||||
if (puestosPersona.Any())
|
||||
{
|
||||
PuestoTrabajo = puestosPersona
|
||||
.OrderByDescending(x => x.IDRPTNavigation.F_PARLAMENTO.Value)
|
||||
.First();
|
||||
|
||||
ForAcuJub.DesPuesTrab = PuestoTrabajo.IDRPTDESNavigation.DENOMINACION;
|
||||
}
|
||||
|
||||
if (per.IDDEPARTAMENTO != null)
|
||||
ForAcuJub.Departamento = per.IDDEPARTAMENTONavigation.DESCRIPCION;
|
||||
|
||||
if (PuestoTrabajo != null)
|
||||
{
|
||||
ForAcuJub.CuerpoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.CUERPO1Navigation.DESCRIPCION;
|
||||
|
||||
double Especifico = double.Parse(PuestoTrabajo.IDRPTDESNavigation.ESPECIFICO.ToString());
|
||||
ForAcuJub.ComEsp = Especifico.ToString("##,##0.00") + "€";
|
||||
|
||||
ForAcuJub.GrupoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1;
|
||||
ForAcuJub.NivelPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.IDNIVEL_RPTNavigation.NIVEL1;
|
||||
ForAcuJub.CarOcu = PuestoTrabajo.IDOCUPACIONNavigation.DESCRIPCION;
|
||||
}
|
||||
|
||||
ForAcuJub.MotivoTomaPosesion = motivo;
|
||||
ForAcuJub.texto1 = texto1;
|
||||
ForAcuJub.FechaEfectoTomaPosesion = fechaEfecto;
|
||||
ForAcuJub.FechaEfeEco = fechaEfecto;
|
||||
ForAcuJub.OrganoCompetente = organo;
|
||||
ForAcuJub.FecVenTri = fechaEmision;
|
||||
}
|
||||
|
||||
LisAcuJub.Add(ForAcuJub);
|
||||
|
||||
var pl = context.PLANTILLAS.First(x => x.CODIGO == "ACUCESE");
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisAcuJub).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] DevuelveConsolidacionGrado(
|
||||
string idPersona,
|
||||
string motivo,
|
||||
string texto1,
|
||||
string texto2,
|
||||
string fechaEfecto,
|
||||
string organo,
|
||||
string fechaEmision)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var context = tsGestionAntifraude.NuevoContexto(SoloLectura: true, UseLazyLoadingProxies: false))
|
||||
{
|
||||
PERSONAS per;
|
||||
var LisCumTri = new List<RecTri>();
|
||||
var ForCumTri = new RecTri();
|
||||
|
||||
if (!string.IsNullOrEmpty(idPersona))
|
||||
{
|
||||
int iDPer = Convert.ToInt32(idPersona);
|
||||
per = context.PERSONAS.First(x => x.IDPERSONA == iDPer);
|
||||
|
||||
ForCumTri.Nif = per.NIF;
|
||||
ForCumTri.Apellidos = per.APELLIDOS;
|
||||
ForCumTri.Nombre = per.NOMBRE;
|
||||
ForCumTri.Adscripcion = per.IDADSCRIPCIONRPTNavigation.DESCRIPCION;
|
||||
ForCumTri.NRP = per.NRP;
|
||||
|
||||
if (per.IDSITUACIONADMINISTRATIVARPT != null)
|
||||
ForCumTri.SitAdm = per.IDSITUACIONADMINISTRATIVARPTNavigation.LITERAL_SITUACION;
|
||||
|
||||
if (per.IDCUERPORPT != null)
|
||||
ForCumTri.Cuerpo = per.IDCUERPORPTNavigation.DESCRIPCION;
|
||||
|
||||
ForCumTri.Grupo = per.GRUPOFUNCIONARIODESCRIPCION;
|
||||
ForCumTri.Localidad = per.NombrePoblacion;
|
||||
ForCumTri.Provincia = per.NombreProvincia;
|
||||
|
||||
var iDSitRptAct = context.ENUMERACIONES.First(x => x.CODIGO == "SITRPTMAESTRO.ACT").IDENUMERACION;
|
||||
PUESTOS PuestoTrabajo = null;
|
||||
|
||||
var puestoActivo = context.PUESTOS
|
||||
.Where(x => x.IDPERSONAL == per.IDPERSONA && x.IDRPTNavigation.IDSITUACION == iDSitRptAct);
|
||||
|
||||
if (puestoActivo.Any())
|
||||
{
|
||||
PuestoTrabajo = puestoActivo.First();
|
||||
ForCumTri.DesPuesTrab = PuestoTrabajo.IDRPTDESNavigation.DENOMINACION;
|
||||
}
|
||||
|
||||
ForCumTri.FechaEfeEco = fechaEfecto;
|
||||
|
||||
if (PuestoTrabajo != null)
|
||||
{
|
||||
ForCumTri.CuerpoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.CUERPO1Navigation.DESCRIPCION;
|
||||
|
||||
double Especifico = double.Parse(PuestoTrabajo.IDRPTDESNavigation.ESPECIFICO.ToString());
|
||||
ForCumTri.ComEsp = Especifico.ToString("##,##0.00") + "€";
|
||||
|
||||
ForCumTri.GrupoPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.GRUPO1Navigation.GRUPO1;
|
||||
ForCumTri.NivelPuestoTrabajo = PuestoTrabajo.IDRPTDESNavigation.IDNIVEL_RPTNavigation.NIVEL1;
|
||||
ForCumTri.CarOcu = PuestoTrabajo.IDOCUPACIONNavigation.DESCRIPCION;
|
||||
}
|
||||
|
||||
ForCumTri.texto1 = texto1;
|
||||
ForCumTri.texto2 = texto2;
|
||||
ForCumTri.texto3 = motivo;
|
||||
}
|
||||
|
||||
LisCumTri.Add(ForCumTri);
|
||||
|
||||
var pl = context.PLANTILLAS.First(x => x.CODIGO == "CONGRA");
|
||||
var idPlantilla = pl.IDPLANTILLA;
|
||||
|
||||
var sFicherohtmlTmp = tsUtilidades.Utilidades.ObtieneFicheroAleatorio("pdf");
|
||||
|
||||
return tsWPFCore.tsXtraReport.ExportarAPDF(pl.IDFICHERONavigation.FICHERO, LisCumTri).ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
235
Antifraude.Net/SwaggerAntifraude/Servicios/ServiciosGestion.cs
Normal file
235
Antifraude.Net/SwaggerAntifraude/Servicios/ServiciosGestion.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
using bdAntifraude.db;
|
||||
using bdAntifraude;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Renci.SshNet;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Cryptography;
|
||||
using tsUtilidades.Enumeraciones;
|
||||
using tsUtilidades;
|
||||
|
||||
namespace SwaggerAntifraude.Servicios
|
||||
{
|
||||
public class ServiciosGestion
|
||||
{
|
||||
|
||||
private static void GuardandoCambiosNomina(object sender, EventArgs e)
|
||||
{
|
||||
//OAEntities bd = (OAEntities)sender;
|
||||
|
||||
////
|
||||
//// ELIMINACION DE NOMINAS
|
||||
////
|
||||
//var NominasEliminadas = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted).Where(x => x.EntitySet.Name == "NOMINATRABAJADORCABECERA").ToList();
|
||||
//if (NominasEliminadas.Count > 0)
|
||||
//{
|
||||
// SftpClient sftp;
|
||||
// sftp = ConectaServidorSftp(bd);
|
||||
// sftp.Connect();
|
||||
// foreach (var n in NominasEliminadas)
|
||||
// {
|
||||
// int idTr = n.OriginalValues("IDPERSONA");
|
||||
// int Año = n.OriginalValues("AÑONOMINA");
|
||||
// int Mes = n.OriginalValues("MESNOMINA");
|
||||
// bool EsDieta = n.OriginalValues("ESLIQUIDACIONDIPUTADO").ToString();
|
||||
// string Fichero;
|
||||
// if (EsDieta)
|
||||
// {
|
||||
// Fichero = "nominas/dietas/" + Año.ToString() + "/" + Mes.ToString().PadLeft(2, '0') + "/" + Año.ToString() + Mes.ToString().PadLeft(2, '0') + "-" + idTr.ToString() + ".pdf";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Fichero = "ordinarias/" + Año.ToString() + "/" + Mes.ToString().PadLeft(2, '0') + "/" + Año.ToString() + Mes.ToString().PadLeft(2, '0') + "-" + idTr.ToString() + ".pdf";
|
||||
// }
|
||||
// if (sftp.Exists(Fichero))
|
||||
// sftp.DeleteFile(Fichero);
|
||||
// }
|
||||
// sftp.Disconnect();
|
||||
//}
|
||||
//if (bd.NivelLog != NivelLogs.SIN_LOGS)
|
||||
//{
|
||||
// IEnumerable<ObjectStateEntry> om;
|
||||
// om = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Added);
|
||||
// foreach (var o in om)
|
||||
// {
|
||||
// if (o.Entity.GetType().GetProperties.Any(X => X.Name == "IDUSUARIOALTA"))
|
||||
// {
|
||||
// var c = o.Entity.GetType().GetProperty("IDUSUARIOALTA");
|
||||
// c.SetValue(o.Entity, dsc.idUsuario);
|
||||
// }
|
||||
|
||||
// if (o.Entity.GetType().GetProperties.Any(X => Operators.ConditionalCompareObjectEqual(X.Name, "FECHAREGISTRONUEVO", false)))
|
||||
// {
|
||||
// var c = o.Entity.GetType().GetProperty("FECHAREGISTRONUEVO");
|
||||
// c.SetValue(o.Entity, Utilidades.AhoraOracle(bd));
|
||||
// }
|
||||
// }
|
||||
// om = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified);
|
||||
// foreach (var o in om)
|
||||
// {
|
||||
// if (o.Entity.GetType().GetProperties.Any(X => Operators.ConditionalCompareObjectEqual(X.Name, "IDUSUARIOMODIFICA", false)))
|
||||
// {
|
||||
// var c = o.Entity.GetType().GetProperty("IDUSUARIOMODIFICA");
|
||||
// c.SetValue(o.Entity, dsc.idUsuario);
|
||||
// }
|
||||
|
||||
// if (o.Entity.GetType().GetProperties.Any(X => Operators.ConditionalCompareObjectEqual(X.Name, "FECHAREGISTROMODIFICADO", false)))
|
||||
// {
|
||||
// var c = o.Entity.GetType().GetProperty("FECHAREGISTROMODIFICADO");
|
||||
// c.SetValue(o.Entity, Utilidades.AhoraOracle(bd));
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (bd.NivelLog == NivelLogs.MODIFICACIONES_Y_ELIMINACIONES)
|
||||
// {
|
||||
// om = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified + EntityState.Deleted);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// om = bd.ObjectStateManager.GetObjectStateEntries(EntityState.Modified + EntityState.Added + EntityState.Deleted);
|
||||
// }
|
||||
// // End If
|
||||
|
||||
// foreach (var o in om)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// string CampoTimeStamp = o.Entity.GetType().GetProperties.Any(X => Operators.ConditionalCompareObjectEqual(X.Name, "IDTIMESPAN", false)) ? "IDTIMESPAN" : "";
|
||||
// var nl = new LOGS();
|
||||
// if (!EntidadesExcluidas.Contains(o.EntitySet.Name.ToLower))
|
||||
// {
|
||||
// nl.TABLA = o.EntitySet.Name;
|
||||
// try
|
||||
// {
|
||||
// nl.ID = (long)o.EntityKey.EntityKeyValues.First.Value;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// }
|
||||
// var lpm = new List<string>();
|
||||
// switch (o.State)
|
||||
// {
|
||||
// case var @case when @case == EntityState.Added:
|
||||
// {
|
||||
// nl.IDTIPO = TipoLog.ALTA;
|
||||
// lpm = o.CurrentValues.DataRecordInfo.FieldMetadata.Select(x => x.FieldType.ToString).ToList;
|
||||
// if (o.Entity.GetType().GetProperties.Any(X => Operators.ConditionalCompareObjectEqual(X.Name, "IDTIMESPAN", false)))
|
||||
// {
|
||||
// var cts = o.Entity.GetType().GetProperty("IDTIMESPAN");
|
||||
// double ticks = DateTime.Now.Ticks;
|
||||
// cts.SetValue(o.Entity, ticks);
|
||||
// nl.IDTIMESTAMP = ticks;
|
||||
// }
|
||||
|
||||
// break;
|
||||
// }
|
||||
// case var case1 when case1 == EntityState.Deleted:
|
||||
// {
|
||||
// nl.IDTIPO = TipoLog.ELIMINACION;
|
||||
// break;
|
||||
// }
|
||||
// case var case2 when case2 == EntityState.Modified:
|
||||
// {
|
||||
// nl.IDTIPO = TipoLog.MODIFICACION;
|
||||
// lpm = o.GetModifiedProperties.ToList;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// nl.USUARIO = Usuario;
|
||||
// nl.FECHAHORA = AhoraOracle(bd);
|
||||
// nl.IP = bd.ip;
|
||||
// nl.APLICACION = bd.Aplicacion;
|
||||
// nl.IDCONEXION = bd.idConexion;
|
||||
// var rl = new RegistroLog();
|
||||
// if (o.State == EntityState.Deleted)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// for (int i = 0, loopTo = o.OriginalValues.FieldCount - 1; i <= loopTo; i++)
|
||||
// {
|
||||
// var ol = new CampoLog();
|
||||
// ol.NombreCampo = o.OriginalValues.GetName(i);
|
||||
// ol.ValorAnterior = nl.ID.ToString;
|
||||
// rl.CamposLog.Add(ol);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.Write(ex.Message);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// foreach (var p in lpm)
|
||||
// {
|
||||
// var tipo = o.Entity.GetType().GetProperty(p).PropertyType;
|
||||
// // Dim stipo = tipo.ToString
|
||||
// // Dim sTipoBase = tipo.BaseType.ToString
|
||||
// try
|
||||
// {
|
||||
// var ol = new CampoLog();
|
||||
// ol.NombreCampo = p;
|
||||
// // If Not (tipo Is GetType(Byte()) Or p.ToLower = "entitykey" Or stipo.ToLower.Contains("entitycollection") Or stipo.ToLower.Contains("entityreference") Or sTipoBase.ToLower.Contains("entityobject")) Then
|
||||
// if (!object.ReferenceEquals(tipo, typeof(byte[])))
|
||||
// {
|
||||
// switch (o.State)
|
||||
// {
|
||||
// case var case3 when case3 == EntityState.Added:
|
||||
// {
|
||||
// if (o.CurrentValues(p) is not null)
|
||||
// ol.ValorNuevo = o.CurrentValues(p).ToString;
|
||||
// break;
|
||||
// }
|
||||
|
||||
// default:
|
||||
// {
|
||||
// if (o.OriginalValues(p) is not null)
|
||||
// ol.ValorAnterior = o.OriginalValues(p).ToString;
|
||||
// if (o.CurrentValues(p) is not null)
|
||||
// ol.ValorNuevo = o.CurrentValues(p).ToString;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// rl.CamposLog.Add(ol);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.Write(ex.Message);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// nl.LOG = tsl5.Utilidades.Serializar(rl);
|
||||
// bd.AddToLOGS(nl);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.Write(ex.Message);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
//public static bool CompruebaFicheroNomina(NOMINATRABAJADORCABECERA N)
|
||||
//{
|
||||
//var bd = bdAntifraude.Utilidades.NuevaConexion(bdAntifraude.Utilidades.ObtieneCBD());
|
||||
//SftpClient sftp = ConectarServidorSftp(bd);
|
||||
//sftp.Connect();
|
||||
//string Fichero = "";
|
||||
//if (N.ESLIQUIDACIONDIPUTADO == true)
|
||||
//{
|
||||
// Fichero = "nominas/dietas/" + N.IDNOMINANavigation?.AÑO.ToString() + "/" + N.IDNOMINANavigation?.DESCRIPCION + "/" + N.IDNOMINANavigation?.AÑO.ToString() + N.IDNOMINANavigation?.MES.ToString().PadLeft(2, '0') + "-" + N.IDPERSONA.ToString() + ".pdf";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Fichero = "ordinarias/" + N.IDNOMINANavigation?.AÑO.ToString() + "/" + N.IDNOMINANavigation?.DESCRIPCION + "/" + N.IDNOMINANavigation?.AÑO.ToString() + N.IDNOMINANavigation?.MES.ToString().PadLeft(2, '0') + "-" + N.IDPERSONA.ToString() + ".pdf";
|
||||
//}
|
||||
//bool result = sftp.Exists(Fichero);
|
||||
//sftp.Disconnect();
|
||||
//return result;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
39
Antifraude.Net/SwaggerAntifraude/SwaggerAntifraude.csproj
Normal file
39
Antifraude.Net/SwaggerAntifraude/SwaggerAntifraude.csproj
Normal file
@@ -0,0 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup Label="Globals">
|
||||
<SccProjectName>%24/tecnosis.tfs/Clientes/ANTIFRAUDE.NET/Antifraude.Net/SwaggerAntifraude</SccProjectName>
|
||||
<SccProvider>{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}</SccProvider>
|
||||
<SccAuxPath>http://ts-devopss:81/tecnosiscollection</SccAuxPath>
|
||||
<SccLocalPath>.</SccLocalPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
||||
<PackageReference Include="Serialize.Linq" Version="3.1.160" />
|
||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.1" />
|
||||
<PackageReference Include="System.Linq" Version="4.3.0" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\bdAntifraude\bdAntifraude.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="tsUtilidades">
|
||||
<HintPath>..\..\..\..\Comun\tsUtilidades\bin\Debug\net8.0\tsUtilidades.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="tsWPFCore">
|
||||
<HintPath>..\..\..\..\Comun\tsWPFCore\bin\Debug\net8.0-windows\tsWPFCore.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
Antifraude.Net/SwaggerAntifraude/SwaggerAntifraude.http
Normal file
6
Antifraude.Net/SwaggerAntifraude/SwaggerAntifraude.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@SwaggerAntifraude_HostAddress = http://localhost:5117
|
||||
|
||||
GET {{SwaggerAntifraude_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Antifraude.Net/SwaggerAntifraude/appsettings.json
Normal file
26
Antifraude.Net/SwaggerAntifraude/appsettings.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"Jwt": {
|
||||
"Key": "TuClaveSecretaMuySegura_1234567890",
|
||||
"Issuer": "TuDominio.com",
|
||||
"Audience": "TuDominio.com",
|
||||
"ExpiresInMinutes": 60
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"WriteConnection": "DATA SOURCE=192.168.41.203:21521/XE;PASSWORD=antifraude2022;PERSIST SECURITY INFO=True;USER ID=ANTIFRAUDEDESARROLLO",
|
||||
"ReadOnlyConnection": "DATA SOURCE=192.168.41.203:21521/XE;PASSWORD=antifraude2022;PERSIST SECURITY INFO=True;USER ID=ANTIFRAUDEDESARROLLO"
|
||||
},
|
||||
//PRODUCCION
|
||||
//"ConnectionStrings": {
|
||||
// "WriteConnection": "DATA SOURCE=192.168.41.203:21521/XE;PASSWORD=antifraude2022;PERSIST SECURITY INFO=True;USER ID=ANTIFRAUDE",
|
||||
// "ReadOnlyConnection": "DATA SOURCE=192.168.41.203:21521/XE;PASSWORD=antifraude2022;PERSIST SECURITY INFO=True;USER ID=ANTIFRAUDE"
|
||||
//},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
//"BaseDatos": "preproduccion",
|
||||
"BaseDatos": "produccion",
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
23
Antifraude.Net/SwaggerAntifraude/web.config
Normal file
23
Antifraude.Net/SwaggerAntifraude/web.config
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<!-- Eliminar WebDAV si estuviera cargado -->
|
||||
<modules runAllManagedModulesForAllRequests="true">
|
||||
<remove name="WebDAVModule" />
|
||||
</modules>
|
||||
|
||||
<handlers>
|
||||
<!-- Eliminar WebDAV si estuviera definido -->
|
||||
<remove name="WebDAV" />
|
||||
|
||||
<!-- Permitir PUT, DELETE y otros métodos HTTP -->
|
||||
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
|
||||
<add name="ExtensionlessUrlHandler-Integrated-4.0"
|
||||
path="*"
|
||||
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
|
||||
type="System.Web.Handlers.TransferRequestHandler"
|
||||
resourceType="Unspecified"
|
||||
preCondition="integratedMode,runtimeVersionv4.0"/>
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user