Arreglado fallo de aunteticación y agregado endpoint de subir archivo (sin probar)
This commit is contained in:
110
APIFicheros/Controllers/ManipularFicherosController.cs
Normal file
110
APIFicheros/Controllers/ManipularFicherosController.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
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
|
||||
{
|
||||
|
||||
byte[] contenidoFichero;
|
||||
var ms = new MemoryStream();
|
||||
datosFichero.fichero.CopyTo(ms);
|
||||
contenidoFichero = ms.ToArray();
|
||||
|
||||
int idFichero = Utilidades.guardarFichero(bd, contenidoFichero, datosFichero.fichero.FileName, datosFichero.descripcion);
|
||||
|
||||
|
||||
documentospolizassg documentoObtenido = bd.documentospolizassg.First( x => x.idDocumento == datosFichero.idDocumento);
|
||||
|
||||
documentoObtenido.idFichero = idFichero;
|
||||
|
||||
bd.Update(documentoObtenido);
|
||||
|
||||
bd.SaveChanges();
|
||||
|
||||
transaction.Commit();
|
||||
return Ok();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return BadRequest("Ha ocurrido un error. Mensaje de error: " + ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user