Refinamiento de permisos y ajustes en controles. Añade gestión sobre saldos y visualización. Entre otros..
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Dapper;
|
||||
using GestionIntegral.Api.Data.Repositories;
|
||||
using GestionIntegral.Api.Dtos.Empresas;
|
||||
using GestionIntegral.Api.Models.Distribucion;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@@ -52,6 +53,25 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<EmpresaDropdownDto>> GetAllDropdownAsync()
|
||||
{
|
||||
var sqlBuilder = new StringBuilder("SELECT Id_Empresa AS IdEmpresa, Nombre FROM dbo.dist_dtEmpresas WHERE 1=1");
|
||||
var parameters = new DynamicParameters();
|
||||
sqlBuilder.Append(" ORDER BY Nombre;");
|
||||
try
|
||||
{
|
||||
using (var connection = _connectionFactory.CreateConnection())
|
||||
{
|
||||
return await connection.QueryAsync<EmpresaDropdownDto>(sqlBuilder.ToString(), parameters);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener todas las Empresas.");
|
||||
return Enumerable.Empty<EmpresaDropdownDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Empresa?> GetByIdAsync(int id)
|
||||
{
|
||||
var sql = "SELECT Id_Empresa AS IdEmpresa, Nombre, Detalle FROM dbo.dist_dtEmpresas WHERE Id_Empresa = @Id";
|
||||
@@ -69,6 +89,23 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Empresa?> ObtenerLookupPorIdAsync(int id)
|
||||
{
|
||||
var sql = "SELECT Id_Empresa AS IdEmpresa, Nombre FROM dbo.dist_dtEmpresas WHERE Id_Empresa = @Id";
|
||||
try
|
||||
{
|
||||
using (var connection = _connectionFactory.CreateConnection())
|
||||
{
|
||||
return await connection.QuerySingleOrDefaultAsync<Empresa>(sql, new { Id = id });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener Empresa por ID: {IdEmpresa}", id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ExistsByNameAsync(string nombre, int? excludeId = null)
|
||||
{
|
||||
var sqlBuilder = new StringBuilder("SELECT COUNT(1) FROM dbo.dist_dtEmpresas WHERE Nombre = @Nombre");
|
||||
@@ -144,7 +181,8 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}
|
||||
|
||||
// Insertar en historial
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new {
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new
|
||||
{
|
||||
IdEmpresa = insertedEmpresa.IdEmpresa,
|
||||
insertedEmpresa.Nombre,
|
||||
insertedEmpresa.Detalle,
|
||||
@@ -172,7 +210,8 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
VALUES (@IdEmpresa, @NombreActual, @DetalleActual, @IdUsuario, @FechaMod, @TipoMod);";
|
||||
|
||||
// Insertar en historial (estado anterior)
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new {
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new
|
||||
{
|
||||
IdEmpresa = empresaActual.IdEmpresa,
|
||||
NombreActual = empresaActual.Nombre,
|
||||
DetalleActual = empresaActual.Detalle,
|
||||
@@ -182,7 +221,8 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}, transaction: transaction);
|
||||
|
||||
// Actualizar principal
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlUpdate, new {
|
||||
var rowsAffected = await transaction.Connection!.ExecuteAsync(sqlUpdate, new
|
||||
{
|
||||
empresaAActualizar.Nombre,
|
||||
empresaAActualizar.Detalle,
|
||||
empresaAActualizar.IdEmpresa
|
||||
@@ -202,7 +242,8 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
VALUES (@IdEmpresa, @Nombre, @Detalle, @IdUsuario, @FechaMod, @TipoMod);";
|
||||
|
||||
// Insertar en historial (estado antes de borrar)
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new {
|
||||
await transaction.Connection!.ExecuteAsync(sqlInsertHistorico, new
|
||||
{
|
||||
IdEmpresa = empresaActual.IdEmpresa,
|
||||
empresaActual.Nombre,
|
||||
empresaActual.Detalle,
|
||||
|
||||
Reference in New Issue
Block a user