using Dapper; using Npgsql; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Ventas.API.Controllers; [ApiController] [Route("api/[controller]")] [Authorize] public class TarifaController : ControllerBase { private readonly string _connectionString; public TarifaController(IConfiguration configuration) => _connectionString = configuration.GetConnectionString("Default")!; [HttpGet] public async Task Buscar([FromQuery] int producto, [FromQuery] int programa, [FromQuery] int jornada, [FromQuery] int sede, [FromQuery] string fecha) { using var connection = new NpgsqlConnection(_connectionString); var rows = await connection.QueryAsync("sige_sam_v3.BuscarTarifa", new { producto, programa, jornada, sede, fecha }, commandType: System.Data.CommandType.StoredProcedure); return Ok(rows.Select(r => (Dictionary)(IDictionary)r!)); } [HttpGet("promocion")] public async Task Promocion([FromQuery] int tarifaId, [FromQuery] int cantidadCursos) { using var connection = new NpgsqlConnection(_connectionString); var rows = await connection.QueryAsync("sige_sam_v3.BuscarTarifaPromocion", new { tarifa = tarifaId, cantcursos = cantidadCursos }, commandType: System.Data.CommandType.StoredProcedure); return Ok(rows.Select(r => (Dictionary)(IDictionary)r!)); } }