105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using APIFicheros.DTOs;
|
|
using bdAsegasa;
|
|
using bdAsegasa.db;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using static Org.BouncyCastle.Math.EC.ECCurve;
|
|
|
|
namespace APIFicheros.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class ManipularFicherosController : Controller
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private bdAsegasa.tscgestionasegasa bd;
|
|
public ManipularFicherosController(IConfiguration configuration)
|
|
{
|
|
|
|
_configuration = configuration;
|
|
|
|
var nombreConexion = _configuration["Configuracion:NombreConexionBD"];
|
|
|
|
bd = tscgestionasegasa.NuevoContexto(nombreConexion, true, false, true, "ObtenerFicheros");
|
|
|
|
}
|
|
|
|
[HttpPost("ObtenerFicherosFaltantes")]
|
|
[Authorize]
|
|
public ActionResult PostComprobarFicheros([FromBody] string numeroPoliza)
|
|
{
|
|
try
|
|
{
|
|
int idPoliza = bd.polizassg.First(x => x.NumeroPoliza!.Contains(numeroPoliza)).idPoliza;
|
|
|
|
|
|
List<bdAsegasa.db.documentospolizassg> listadoDocumentos = new List<bdAsegasa.db.documentospolizassg>();
|
|
List<PolizasFaltantes> listadoFicherosFaltantes = new List<PolizasFaltantes>();
|
|
|
|
listadoDocumentos = bd.documentospolizassg.Where(x => x.idPoliza == idPoliza && x.idFichero == null).ToList();
|
|
|
|
|
|
foreach (documentospolizassg documentoFaltante in listadoDocumentos)
|
|
{
|
|
listadoFicherosFaltantes.Add(new PolizasFaltantes
|
|
{
|
|
idDocumento = documentoFaltante.idDocumento,
|
|
descripcion = documentoFaltante.idDocumentoASolicitarNavigation!.idTipoNavigation!.Descripcion
|
|
});
|
|
}
|
|
|
|
return Ok(listadoFicherosFaltantes);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
return BadRequest("Ha ocurrido un error. Mensaje de error: " + ex.Message);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
[HttpPost("SubirFicherosFaltantes")]
|
|
[Authorize]
|
|
public ActionResult PostSubirFicheros([FromBody] DatosFicheros datosFichero)
|
|
{
|
|
|
|
var transaction = bd.Database.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
int idFichero = Utilidades.guardarFichero(bd, datosFichero.fichero, datosFichero.nombreFichero, datosFichero.descripcion, datosFichero.idDocumento);
|
|
|
|
|
|
documentospolizassg documentoObtenido = bd.documentospolizassg.First( x => x.idDocumento == datosFichero.idDocumento);
|
|
|
|
documentoObtenido.idFichero = idFichero;
|
|
|
|
bd.Update(documentoObtenido);
|
|
|
|
bd.SaveChanges();
|
|
|
|
transaction.Commit();
|
|
return Ok("Fichero subido correctamente");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
transaction.Rollback();
|
|
return BadRequest("Ha ocurrido un error. Mensaje de error: " + ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|