diff --git a/Contracts/Catalogos/ICatCentrosCostos.cs b/Contracts/Catalogos/ICatCentrosCostos.cs new file mode 100644 index 0000000..06d9812 --- /dev/null +++ b/Contracts/Catalogos/ICatCentrosCostos.cs @@ -0,0 +1,12 @@ +using CORRESPONSALBackend.DTO; +using CORRESPONSALBackend.Models.Catalogos; + +namespace CORRESPONSALBackend.Contracts.Catalogos +{ + public interface ICatCentrosCostosRepository + { + public Task> GetAll(); + public Task> Append(CatCentrosCostos centroCostos); + public Task Get(int idCliente); + } +} \ No newline at end of file diff --git a/Controllers/Catalogos/CatCentrosCostosController.cs b/Controllers/Catalogos/CatCentrosCostosController.cs new file mode 100644 index 0000000..d642d54 --- /dev/null +++ b/Controllers/Catalogos/CatCentrosCostosController.cs @@ -0,0 +1,40 @@ +using CORRESPONSALBackend.Contracts.Catalogos; +using CORRESPONSALBackend.DTO; +using CORRESPONSALBackend.Models.Catalogos; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace CORRESPONSALBackend.Controllers.Catalogos +{ + [Authorize] + [Route("api/Catalogos/[controller]")] + public class CatCentrosCostosController : Controller + { + private readonly ICatCentrosCostosRepository _repo; + + public CatCentrosCostosController(ICatCentrosCostosRepository repo){ + _repo = repo; + } + [HttpGet("GetAll")] + public async Task> GetAll(){ + var centrosCostos = await _repo.GetAll(); + return centrosCostos; + } + + [HttpGet] + public async Task Get([FromQuery] int idCliente){ + var centroCostos = await _repo.Get(idCliente); + return centroCostos; + } + + [HttpPost("Append")] + public async Task> Append([FromBody] CatCentrosCostos centroCostos){ + try{ + var centrosCostos = await _repo.Append(centroCostos); + return centrosCostos; + }catch(Exception ex){ + throw new Exception(ex.Message); + } + } + } +} \ No newline at end of file diff --git a/DTO/DTOCentrosCostos.cs b/DTO/DTOCentrosCostos.cs new file mode 100644 index 0000000..ada0247 --- /dev/null +++ b/DTO/DTOCentrosCostos.cs @@ -0,0 +1,10 @@ +namespace CORRESPONSALBackend.DTO +{ + public class DTOCentrosCostos + { + public int id { set; get; } = 0; + public int idCliente { get; set; } + public string CentroCostos { get; set; } + public string NombreCliente {get;set;} + } +} \ No newline at end of file diff --git a/Models/Catalogos/CatCentrosCostos.cs b/Models/Catalogos/CatCentrosCostos.cs new file mode 100644 index 0000000..cdc4e29 --- /dev/null +++ b/Models/Catalogos/CatCentrosCostos.cs @@ -0,0 +1,9 @@ +namespace CORRESPONSALBackend.Models.Catalogos +{ + public class CatCentrosCostos + { + public int id { set; get; } = 0; + public int idCliente { get; set; } + public string CentroCostos { get; set; } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index d9e0475..3a6f7db 100644 --- a/Program.cs +++ b/Program.cs @@ -74,6 +74,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); //Utilerias builder.Services.AddScoped(); diff --git a/Repository/Catalogos/CatCentrosCostosRepository.cs b/Repository/Catalogos/CatCentrosCostosRepository.cs new file mode 100644 index 0000000..cc581b1 --- /dev/null +++ b/Repository/Catalogos/CatCentrosCostosRepository.cs @@ -0,0 +1,45 @@ + + +using System.Data; +using CORRESPONSALBackend.Context; +using CORRESPONSALBackend.Contracts.Catalogos; +using CORRESPONSALBackend.DTO; +using CORRESPONSALBackend.Models.Catalogos; +using Dapper; + +namespace CORRESPONSALBackend.Repository.Catalogos +{ + public class CatCentrosCostosRepository : ICatCentrosCostosRepository + { + private readonly DapperContext _context; + public CatCentrosCostosRepository(DapperContext context) { _context = context; } + + public async Task> Append(CatCentrosCostos centroCostos) + { + var query = "[Catalogo.CatCentrosCostos.Append]"; + using var connection = _context.CreateConnection(); + var centrosCostos = await connection.QueryAsync(query, new { + @id = centroCostos.id, + @idCliente = centroCostos.idCliente, + @centroCostos = centroCostos.CentroCostos + }, commandType: CommandType.StoredProcedure); + return centrosCostos.ToList(); + } + + public async Task> GetAll() + { + var query = "[Catalogo.CatCentrosCostos.GetAll]"; + using var connection = _context.CreateConnection(); + var centrosCostos = await connection.QueryAsync(query, new {}, commandType: CommandType.StoredProcedure); + return centrosCostos.ToList(); + } + + public async Task Get(int idCliente) + { + var query = "[Catalogo.CatCentrosCostos.Get]"; + using var connection = _context.CreateConnection(); + var centrosCostos = await connection.ExecuteScalarAsync(query, new {@idCliente = idCliente}, commandType: CommandType.StoredProcedure); + return centrosCostos; + } + } +} \ No newline at end of file