Refactor services to use repository pattern for database operations
- Updated EmpresaReportService to utilize ICatalogoRepository for stored procedure calls. - Refactored InformeService to include new method for executing Crystal Reports stored procedures. - Simplified LeadService by removing direct database connections and using ILeadRepository and ILeadQueryRepository. - Modified ReportService to leverage ICatalogoRepository for querying stored procedures. - Streamlined UsuarioService to use IUsuarioRepository for user authentication and profile retrieval. - Added new CatalogoService to handle various catalog-related queries and operations. - Introduced ArqueoRepository and CatalogoRepository for managing database interactions. - Created DTOs for various entities including Alumno, Contrato, Cotizacion, Descuento, Documento, Empresa, and Propuesta. - Implemented BaseController and ErrorController for standardized API responses and error handling. - Added QuestPDF package for PDF generation capabilities.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Dapper;
|
||||
using Npgsql;
|
||||
using Ventas.Core.Interfaces;
|
||||
|
||||
namespace Ventas.Infrastructure.Repositories;
|
||||
|
||||
public class CatalogoRepository : ICatalogoRepository
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
public CatalogoRepository(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Dictionary<string, object>>> QuerySpAsync(string sp, object parameters)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
var rows = await connection.QueryAsync(sp, parameters, commandType: System.Data.CommandType.StoredProcedure);
|
||||
return rows.Select(r => (Dictionary<string, object>)(IDictionary<string, object>)r!);
|
||||
}
|
||||
|
||||
public async Task<string> ExecuteSpAsync(string sp, object parameters)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
await connection.ExecuteAsync(sp, parameters, commandType: System.Data.CommandType.StoredProcedure);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
public async Task<string?> QuerySingleSpAsync(string sp, object parameters)
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString);
|
||||
return await connection.QuerySingleOrDefaultAsync<string>(sp, parameters,
|
||||
commandType: System.Data.CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user