using Dapper; using Npgsql; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Ventas.API.Controllers; [ApiController] [Route("api/[controller]")] [Authorize] public class DescuentoController : ControllerBase { private readonly string _connectionString; public DescuentoController(IConfiguration configuration) { _connectionString = configuration.GetConnectionString("Default")!; } [HttpGet] public async Task Buscar([FromQuery] string tipoBusqueda, [FromQuery] int sede, [FromQuery] int programa, [FromQuery] int horario) { using var connection = new NpgsqlConnection(_connectionString); var rows = await connection.QueryAsync("sige_sam_v3.BuscarDescuentos", new { tipobusqueda = tipoBusqueda, sedeid = sede, programaid = programa, horarioid = horario }, commandType: System.Data.CommandType.StoredProcedure); return Ok(rows.Select(r => (Dictionary)(IDictionary)r!)); } [HttpGet("summer")] public async Task Summer([FromQuery] int cantidadCursos) { using var connection = new NpgsqlConnection(_connectionString); var rows = await connection.QueryAsync("sige_sam_v3.BuscarDesctoSummer", new { cantidad = cantidadCursos }, commandType: System.Data.CommandType.StoredProcedure); return Ok(rows.Select(r => (Dictionary)(IDictionary)r!)); } [HttpPost] public async Task Ingresar([FromQuery] int cotizacionId, [FromQuery] int descuentoId, [FromQuery] int tipoDescuento, [FromQuery] int nuevoMonto) { using var connection = new NpgsqlConnection(_connectionString); await connection.ExecuteAsync("sige_sam_v3.DescuentoCotizacion", new { cotiid = cotizacionId, desctoid = descuentoId, tipoid = tipoDescuento, nuevototal = nuevoMonto }, commandType: System.Data.CommandType.StoredProcedure); return Ok(new { mensaje = "ok" }); } }