93 lines
2.4 KiB
C#
93 lines
2.4 KiB
C#
|
|
using AutoMapper;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Microsoft.Extensions.Logging;
|
|||
|
|
using REC_HUMA.CORE.DTOs;
|
|||
|
|
using REC_HUMA.CORE.Entities;
|
|||
|
|
using REC_HUMA.CORE.Interfaces;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace REC_HUMA.API.Controllers
|
|||
|
|
{
|
|||
|
|
[Route("api/[controller]")]
|
|||
|
|
[ApiController]
|
|||
|
|
public class PaisController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly IPaisRepo _PaisRepo;
|
|||
|
|
private readonly IMapper _mapper;
|
|||
|
|
private readonly ILogger<Pais> _logger;
|
|||
|
|
|
|||
|
|
public PaisController(IPaisRepo PaisRepo, IMapper mapper, ILogger<Pais> logger)
|
|||
|
|
{
|
|||
|
|
_PaisRepo = PaisRepo;
|
|||
|
|
_mapper = mapper;
|
|||
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public async Task<IEnumerable<PaisDto>> GetPaises()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var paises = await _PaisRepo.GetPaises();
|
|||
|
|
|
|||
|
|
var paisesDto = _mapper.Map<IEnumerable<PaisDto>>(paises);
|
|||
|
|
|
|||
|
|
return paisesDto;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
var paisesDto = new List<PaisDto>
|
|||
|
|
{
|
|||
|
|
new PaisDto() { CodResultado = 500, Mensaje = "Error" }
|
|||
|
|
};
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return paisesDto;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet("{id}")]
|
|||
|
|
public async Task<PaisDto> GetPais(int id)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var pais = await _PaisRepo.GetPais(id);
|
|||
|
|
var paisDto = _mapper.Map<PaisDto>(pais);
|
|||
|
|
|
|||
|
|
return paisDto;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
var paisDto = new PaisDto
|
|||
|
|
{
|
|||
|
|
CodResultado = 500,
|
|||
|
|
Mensaje = "Error"
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return paisDto;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//[HttpPut]
|
|||
|
|
//public async Task<IActionResult> PutBanco(BancoDto bancoDto)
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//[HttpPost]
|
|||
|
|
//public async Task<IActionResult> PostBanco(BancoDto bancoDto)
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//[HttpDelete("{id}")]
|
|||
|
|
//public async Task<IActionResult> DeleteBanco(int id)
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|