Fix: Quita Archivos de DB Unificadas Sobrantes
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MotoresArgentinosV2.Core.Entities;
|
||||
using MotoresArgentinosV2.Core.Interfaces;
|
||||
|
||||
namespace MotoresArgentinosV2.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class OperacionesLegacyController : ControllerBase
|
||||
{
|
||||
private readonly IOperacionesLegacyService _operacionesService;
|
||||
private readonly ILogger<OperacionesLegacyController> _logger;
|
||||
|
||||
public OperacionesLegacyController(IOperacionesLegacyService operacionesService, ILogger<OperacionesLegacyController> logger)
|
||||
{
|
||||
_operacionesService = operacionesService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene los medios de pago disponibles
|
||||
/// </summary>
|
||||
[HttpGet("medios-pago")]
|
||||
public async Task<ActionResult<List<MedioDePago>>> GetMediosDePago()
|
||||
{
|
||||
try
|
||||
{
|
||||
var medios = await _operacionesService.ObtenerMediosDePagoAsync();
|
||||
return Ok(medios);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener medios de pago");
|
||||
return StatusCode(500, "Ocurrió un error interno al obtener medios de pago");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Busca una operación por su número de operación
|
||||
/// </summary>
|
||||
[HttpGet("{noperacion}")]
|
||||
public async Task<ActionResult<List<Operacion>>> GetOperacion(string noperacion)
|
||||
{
|
||||
try
|
||||
{
|
||||
var operaciones = await _operacionesService.ObtenerOperacionesPorNumeroAsync(noperacion);
|
||||
|
||||
if (operaciones == null || !operaciones.Any())
|
||||
{
|
||||
return NotFound($"No se encontraron operaciones con el número {noperacion}");
|
||||
}
|
||||
|
||||
return Ok(operaciones);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener operación {Noperacion}", noperacion);
|
||||
return StatusCode(500, "Ocurrió un error interno al buscar la operación");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene operaciones realizadas en un rango de fechas
|
||||
/// </summary>
|
||||
[HttpGet("buscar")]
|
||||
public async Task<ActionResult<List<Operacion>>> GetOperacionesPorFecha([FromQuery] DateTime fechaInicio, [FromQuery] DateTime fechaFin)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fechaInicio > fechaFin)
|
||||
{
|
||||
return BadRequest("La fecha de inicio no puede ser mayor a la fecha de fin.");
|
||||
}
|
||||
|
||||
var operaciones = await _operacionesService.ObtenerOperacionesPorFechasAsync(fechaInicio, fechaFin);
|
||||
return Ok(operaciones);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al buscar operaciones por fecha");
|
||||
return StatusCode(500, "Ocurrió un error interno al buscar operaciones.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registra una nueva operación de pago
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> CrearOperacion([FromBody] Operacion operacion)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
// Validar campos mínimos necesarios si es necesario
|
||||
if (string.IsNullOrEmpty(operacion.Noperacion))
|
||||
{
|
||||
return BadRequest("El número de operación es obligatorio.");
|
||||
}
|
||||
|
||||
var resultado = await _operacionesService.InsertarOperacionAsync(operacion);
|
||||
|
||||
if (resultado)
|
||||
{
|
||||
return CreatedAtAction(nameof(GetOperacion), new { noperacion = operacion.Noperacion }, operacion);
|
||||
}
|
||||
|
||||
return BadRequest("No se pudo registrar la operación.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al crear operación {Noperacion}", operacion.Noperacion);
|
||||
return StatusCode(500, "Ocurrió un error interno al registrar la operación.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,16 +98,12 @@ builder.Services.Configure<HostOptions>(options =>
|
||||
builder.Services.AddDbContext<InternetDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("Internet")));
|
||||
|
||||
builder.Services.AddDbContext<EldiaDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("eldia")));
|
||||
|
||||
builder.Services.AddDbContext<MotoresV2DbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("MotoresV2"),
|
||||
sqlOptions => sqlOptions.EnableRetryOnFailure()));
|
||||
|
||||
// SERVICIOS
|
||||
builder.Services.AddScoped<IAvisosLegacyService, AvisosLegacyService>();
|
||||
builder.Services.AddScoped<IOperacionesLegacyService, OperacionesLegacyService>();
|
||||
builder.Services.AddScoped<IUsuariosLegacyService, UsuariosLegacyService>();
|
||||
builder.Services.AddScoped<IPasswordService, PasswordService>();
|
||||
builder.Services.AddScoped<IIdentityService, IdentityService>();
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
using MotoresArgentinosV2.Core.Entities;
|
||||
|
||||
namespace MotoresArgentinosV2.Core.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// Interfaz para servicios que interactúan con stored procedures legacy
|
||||
/// relacionados con operaciones de pago
|
||||
/// </summary>
|
||||
public interface IOperacionesLegacyService
|
||||
{
|
||||
/// <summary>
|
||||
/// Ejecuta el SP sp_inserta_operaciones para registrar una nueva operación
|
||||
/// </summary>
|
||||
/// <param name="operacion">Datos de la operación a registrar</param>
|
||||
/// <returns>True si se insertó correctamente</returns>
|
||||
Task<bool> InsertarOperacionAsync(Operacion operacion);
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene operaciones por número de operación
|
||||
/// </summary>
|
||||
/// <param name="noperacion">Número de operación a buscar</param>
|
||||
/// <returns>Lista de operaciones encontradas</returns>
|
||||
Task<List<Operacion>> ObtenerOperacionesPorNumeroAsync(string noperacion);
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene operaciones en un rango de fechas
|
||||
/// </summary>
|
||||
/// <param name="fechaInicio">Fecha inicial</param>
|
||||
/// <param name="fechaFin">Fecha final</param>
|
||||
/// <returns>Lista de operaciones en el rango</returns>
|
||||
Task<List<Operacion>> ObtenerOperacionesPorFechasAsync(DateTime fechaInicio, DateTime fechaFin);
|
||||
|
||||
/// <summary>
|
||||
/// Obtiene todos los medios de pago disponibles
|
||||
/// </summary>
|
||||
/// <returns>Lista de medios de pago</returns>
|
||||
Task<List<MedioDePago>> ObtenerMediosDePagoAsync();
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MotoresArgentinosV2.Core.DTOs;
|
||||
using MotoresArgentinosV2.Core.Entities;
|
||||
|
||||
namespace MotoresArgentinosV2.Infrastructure.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Contexto de Entity Framework unificado para la base de datos 'eldia' (Legacy)
|
||||
/// Contiene las tablas de avisos web, operaciones, medios de pago y lógica de usuarios legacy.
|
||||
/// </summary>
|
||||
public class EldiaDbContext : DbContext
|
||||
{
|
||||
public EldiaDbContext(DbContextOptions<EldiaDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
// Tablas de la base 'autos' (ahora en eldia)
|
||||
public DbSet<Operacion> Operaciones { get; set; }
|
||||
public DbSet<MedioDePago> MediosDePago { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// --- Configuración de tablas ex-Autos ---
|
||||
|
||||
modelBuilder.Entity<Operacion>(entity =>
|
||||
{
|
||||
entity.ToTable("operaciones");
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.Fecha).HasColumnName("fecha");
|
||||
entity.Property(e => e.Motivo).HasColumnName("motivo").HasMaxLength(50);
|
||||
entity.Property(e => e.Moneda).HasColumnName("moneda").HasMaxLength(50);
|
||||
entity.Property(e => e.Direccionentrega).HasColumnName("direccionentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Validaciondomicilio).HasColumnName("validaciondomicilio").HasMaxLength(50);
|
||||
entity.Property(e => e.Codigopedido).HasColumnName("codigopedido").HasMaxLength(50);
|
||||
entity.Property(e => e.Nombreentrega).HasColumnName("nombreentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Fechahora).HasColumnName("fechahora").HasMaxLength(50);
|
||||
entity.Property(e => e.Telefonocomprador).HasColumnName("telefonocomprador").HasMaxLength(50);
|
||||
entity.Property(e => e.Barrioentrega).HasColumnName("barrioentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Codautorizacion).HasColumnName("codautorizacion").HasMaxLength(50);
|
||||
entity.Property(e => e.Paisentrega).HasColumnName("paisentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Cuotas).HasColumnName("cuotas").HasMaxLength(50);
|
||||
entity.Property(e => e.Validafechanac).HasColumnName("validafechanac").HasMaxLength(50);
|
||||
entity.Property(e => e.Validanrodoc).HasColumnName("validanrodoc").HasMaxLength(50);
|
||||
entity.Property(e => e.Titular).HasColumnName("titular").HasMaxLength(50);
|
||||
entity.Property(e => e.Pedido).HasColumnName("pedido").HasMaxLength(50);
|
||||
entity.Property(e => e.Zipentrega).HasColumnName("zipentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Monto).HasColumnName("monto").HasMaxLength(50);
|
||||
entity.Property(e => e.Tarjeta).HasColumnName("tarjeta").HasMaxLength(50);
|
||||
entity.Property(e => e.Fechaentrega).HasColumnName("fechaentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Emailcomprador).HasColumnName("emailcomprador").HasMaxLength(50);
|
||||
entity.Property(e => e.Validanropuerta).HasColumnName("validanropuerta").HasMaxLength(50);
|
||||
entity.Property(e => e.Ciudadentrega).HasColumnName("ciudadentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Validatipodoc).HasColumnName("validatipodoc").HasMaxLength(50);
|
||||
entity.Property(e => e.Noperacion).HasColumnName("noperacion").HasMaxLength(50);
|
||||
entity.Property(e => e.Estadoentrega).HasColumnName("estadoentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Resultado).HasColumnName("resultado").HasMaxLength(50);
|
||||
entity.Property(e => e.Mensajeentrega).HasColumnName("mensajeentrega").HasMaxLength(50);
|
||||
entity.Property(e => e.Precioneto).HasColumnName("precioneto");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MedioDePago>(entity =>
|
||||
{
|
||||
entity.ToTable("mediodepago");
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
entity.Property(e => e.Mediodepago).HasColumnName("mediodepago").HasMaxLength(20);
|
||||
});
|
||||
|
||||
// --- Configuración de DTOs Keyless de ex-Internet ---
|
||||
|
||||
modelBuilder.Entity<DatosAvisoDto>(e =>
|
||||
{
|
||||
e.HasNoKey();
|
||||
e.ToView(null);
|
||||
|
||||
e.Property(p => p.ImporteSiniva).HasColumnType("decimal(18,2)");
|
||||
e.Property(p => p.ImporteTotsiniva).HasColumnType("decimal(18,2)");
|
||||
e.Property(p => p.PorcentajeCombinado).HasColumnType("decimal(18,2)");
|
||||
e.Property(p => p.Centimetros).HasColumnType("decimal(18,2)");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MotoresArgentinosV2.Core.Entities;
|
||||
using MotoresArgentinosV2.Core.Interfaces;
|
||||
using MotoresArgentinosV2.Infrastructure.Data;
|
||||
|
||||
namespace MotoresArgentinosV2.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Implementación del servicio para interactuar con datos legacy de operaciones
|
||||
/// Utiliza EldiaDbContext para acceder a tablas y ejecutar SPs de la DB 'eldia' (ex base de datos 'autos')
|
||||
/// </summary>
|
||||
public class OperacionesLegacyService : IOperacionesLegacyService
|
||||
{
|
||||
private readonly EldiaDbContext _context;
|
||||
private readonly ILogger<OperacionesLegacyService> _logger;
|
||||
|
||||
public OperacionesLegacyService(EldiaDbContext context, ILogger<OperacionesLegacyService> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ejecuta el SP sp_inserta_operaciones para registrar un pago
|
||||
/// </summary>
|
||||
public async Task<bool> InsertarOperacionAsync(Operacion operacion)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Ejecutando sp_inserta_operaciones para operación: {Noperacion}", operacion.Noperacion);
|
||||
|
||||
// Preparar parámetros asegurando manejo de nulos
|
||||
var parameters = new[]
|
||||
{
|
||||
new SqlParameter("@fecha", operacion.Fecha ?? (object)DBNull.Value),
|
||||
new SqlParameter("@Motivo", operacion.Motivo ?? (object)DBNull.Value),
|
||||
new SqlParameter("@Moneda", operacion.Moneda ?? (object)DBNull.Value),
|
||||
new SqlParameter("@Direccionentrega", operacion.Direccionentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@Validaciondomicilio", operacion.Validaciondomicilio ?? (object)DBNull.Value),
|
||||
new SqlParameter("@codigopedido", operacion.Codigopedido ?? (object)DBNull.Value),
|
||||
new SqlParameter("@nombreentrega", operacion.Nombreentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@fechahora", operacion.Fechahora ?? (object)DBNull.Value),
|
||||
new SqlParameter("@telefonocomprador", operacion.Telefonocomprador ?? (object)DBNull.Value),
|
||||
new SqlParameter("@barrioentrega", operacion.Barrioentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@codautorizacion", operacion.Codautorizacion ?? (object)DBNull.Value),
|
||||
new SqlParameter("@paisentrega", operacion.Paisentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@cuotas", operacion.Cuotas ?? (object)DBNull.Value),
|
||||
new SqlParameter("@validafechanac", operacion.Validafechanac ?? (object)DBNull.Value),
|
||||
new SqlParameter("@validanrodoc", operacion.Validanrodoc ?? (object)DBNull.Value),
|
||||
new SqlParameter("@titular", operacion.Titular ?? (object)DBNull.Value),
|
||||
new SqlParameter("@pedido", operacion.Pedido ?? (object)DBNull.Value),
|
||||
new SqlParameter("@zipentrega", operacion.Zipentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@monto", operacion.Monto ?? (object)DBNull.Value),
|
||||
new SqlParameter("@tarjeta", operacion.Tarjeta ?? (object)DBNull.Value),
|
||||
new SqlParameter("@fechaentrega", operacion.Fechaentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@emailcomprador", operacion.Emailcomprador ?? (object)DBNull.Value),
|
||||
new SqlParameter("@validanropuerta", operacion.Validanropuerta ?? (object)DBNull.Value),
|
||||
new SqlParameter("@ciudadentrega", operacion.Ciudadentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@validatipodoc", operacion.Validatipodoc ?? (object)DBNull.Value),
|
||||
new SqlParameter("@noperacion", operacion.Noperacion ?? (object)DBNull.Value),
|
||||
new SqlParameter("@estadoentrega", operacion.Estadoentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@resultado", operacion.Resultado ?? (object)DBNull.Value),
|
||||
new SqlParameter("@mensajeentrega", operacion.Mensajeentrega ?? (object)DBNull.Value),
|
||||
new SqlParameter("@precio", operacion.Precioneto ?? 0) // El SP espera int
|
||||
};
|
||||
|
||||
await _context.Database.ExecuteSqlRawAsync(
|
||||
"EXEC dbo.sp_inserta_operaciones @fecha, @Motivo, @Moneda, @Direccionentrega, " +
|
||||
"@Validaciondomicilio, @codigopedido, @nombreentrega, @fechahora, @telefonocomprador, " +
|
||||
"@barrioentrega, @codautorizacion, @paisentrega, @cuotas, @validafechanac, @validanrodoc, " +
|
||||
"@titular, @pedido, @zipentrega, @monto, @tarjeta, @fechaentrega, @emailcomprador, " +
|
||||
"@validanropuerta, @ciudadentrega, @validatipodoc, @noperacion, @estadoentrega, " +
|
||||
"@resultado, @mensajeentrega, @precio",
|
||||
parameters);
|
||||
|
||||
_logger.LogInformation("Operación registrada correctamente: {Noperacion}", operacion.Noperacion);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al insertar operación: {Noperacion}", operacion.Noperacion);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Operacion>> ObtenerOperacionesPorNumeroAsync(string noperacion)
|
||||
{
|
||||
return await _context.Operaciones
|
||||
.AsNoTracking()
|
||||
.Where(o => o.Noperacion == noperacion)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Operacion>> ObtenerOperacionesPorFechasAsync(DateTime fechaInicio, DateTime fechaFin)
|
||||
{
|
||||
return await _context.Operaciones
|
||||
.AsNoTracking()
|
||||
.Where(o => o.Fecha >= fechaInicio && o.Fecha <= fechaFin)
|
||||
.OrderByDescending(o => o.Fecha)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<MedioDePago>> ObtenerMediosDePagoAsync()
|
||||
{
|
||||
return await _context.MediosDePago
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user