Finalización de Reportes y arreglos varios de controles y comportamientos...
This commit is contained in:
@@ -106,8 +106,8 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
WHERE Id_Publicacion = @IdParam";
|
||||
try
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
return await connection.QuerySingleOrDefaultAsync<Publicacion>(sql, new { IdParam = id });
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
return await connection.QuerySingleOrDefaultAsync<Publicacion>(sql, new { IdParam = id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error en ExistsByNameAndEmpresaAsync. Nombre: {Nombre}, IdEmpresa: {IdEmpresa}", nombre, idEmpresa);
|
||||
_logger.LogError(ex, "Error en ExistsByNameAndEmpresaAsync. Nombre: {Nombre}, IdEmpresa: {IdEmpresa}", nombre, idEmpresa);
|
||||
return true; // Asumir que existe en caso de error para prevenir duplicados
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
INSERT INTO dbo.dist_dtPublicaciones (Nombre, Observacion, Id_Empresa, CtrlDevoluciones, Habilitada)
|
||||
OUTPUT INSERTED.Id_Publicacion AS IdPublicacion, INSERTED.Nombre, INSERTED.Observacion, INSERTED.Id_Empresa AS IdEmpresa, INSERTED.CtrlDevoluciones, INSERTED.Habilitada
|
||||
VALUES (@Nombre, @Observacion, @IdEmpresa, @CtrlDevoluciones, @Habilitada);";
|
||||
|
||||
|
||||
var connection = transaction.Connection!;
|
||||
var inserted = await connection.QuerySingleAsync<Publicacion>(sqlInsert, nuevaPublicacion, transaction);
|
||||
if (inserted == null || inserted.IdPublicacion == 0) throw new DataException("Error al crear la publicación o al obtener el ID generado.");
|
||||
@@ -192,7 +192,7 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
NombreParam = inserted.Nombre,
|
||||
ObservacionParam = inserted.Observacion,
|
||||
IdEmpresaParam = inserted.IdEmpresa,
|
||||
HabilitadaParam = inserted.Habilitada ?? true,
|
||||
HabilitadaParam = inserted.Habilitada ?? true,
|
||||
IdUsuarioParam = idUsuario, // Renombrado para claridad con el parámetro de la función
|
||||
FechaModParam = DateTime.Now,
|
||||
TipoModParam = "Creada"
|
||||
@@ -267,5 +267,65 @@ namespace GestionIntegral.Api.Data.Repositories.Distribucion
|
||||
var rowsAffected = await connection.ExecuteAsync(sqlDelete, new { IdParam = id }, transaction);
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PublicacionDiaSemana>> GetConfiguracionDiasAsync(int idPublicacion)
|
||||
{
|
||||
const string sql = @"
|
||||
SELECT IdPublicacionDia, Id_Publicacion AS IdPublicacion, DiaSemana, Activo
|
||||
FROM dbo.dist_PublicacionDiaSemana
|
||||
WHERE Id_Publicacion = @IdPublicacion AND Activo = 1;"; // Solo los activos
|
||||
try
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
return await connection.QueryAsync<PublicacionDiaSemana>(sql, new { IdPublicacion = idPublicacion });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener configuración de días para Publicacion ID: {IdPublicacion}", idPublicacion);
|
||||
return Enumerable.Empty<PublicacionDiaSemana>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<int>> GetPublicacionesIdsPorDiaSemanaAsync(byte diaSemana)
|
||||
{
|
||||
const string sql = @"
|
||||
SELECT pds.Id_Publicacion
|
||||
FROM dbo.dist_PublicacionDiaSemana pds
|
||||
INNER JOIN dbo.dist_dtPublicaciones p ON pds.Id_Publicacion = p.Id_Publicacion
|
||||
WHERE pds.DiaSemana = @DiaSemana AND pds.Activo = 1 AND (p.Habilitada = 1 OR p.Habilitada IS NULL);"; // Solo publicaciones habilitadas
|
||||
try
|
||||
{
|
||||
using var connection = _connectionFactory.CreateConnection();
|
||||
return await connection.QueryAsync<int>(sql, new { DiaSemana = diaSemana });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error al obtener IDs de publicaciones por día de semana: {DiaSemana}", diaSemana);
|
||||
return Enumerable.Empty<int>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateConfiguracionDiasAsync(int idPublicacion, IEnumerable<byte> diasActivos, IDbTransaction transaction)
|
||||
{
|
||||
var connection = transaction.Connection!;
|
||||
|
||||
// 1. Eliminar configuraciones existentes para esta publicación (más simple que hacer upserts complejos)
|
||||
const string sqlDelete = "DELETE FROM dbo.dist_PublicacionDiaSemana WHERE Id_Publicacion = @IdPublicacion;";
|
||||
await connection.ExecuteAsync(sqlDelete, new { IdPublicacion = idPublicacion }, transaction);
|
||||
|
||||
// 2. Insertar las nuevas configuraciones activas
|
||||
if (diasActivos != null && diasActivos.Any())
|
||||
{
|
||||
const string sqlInsert = @"
|
||||
INSERT INTO dbo.dist_PublicacionDiaSemana (Id_Publicacion, DiaSemana, Activo)
|
||||
VALUES (@IdPublicacion, @DiaSemana, 1);"; // Siempre activo al insertar
|
||||
|
||||
var insertTasks = diasActivos.Select(dia =>
|
||||
connection.ExecuteAsync(sqlInsert, new { IdPublicacion = idPublicacion, DiaSemana = dia }, transaction)
|
||||
);
|
||||
await Task.WhenAll(insertTasks);
|
||||
}
|
||||
// No se necesita historial para esta tabla de configuración por ahora.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user