177 lines
5.8 KiB
C#
177 lines
5.8 KiB
C#
|
|
using AutoMapper;
|
|||
|
|
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.Collections.Generic;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System;
|
|||
|
|
|
|||
|
|
namespace REC_HUMA.API.Controllers
|
|||
|
|
{
|
|||
|
|
[Route("api/[controller]")]
|
|||
|
|
[ApiController]
|
|||
|
|
public class SolicitudVacacionesController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly ISolicitudVacacionesRepo _SolicitudVacacionesRepo;
|
|||
|
|
private readonly IMapper _mapper;
|
|||
|
|
private readonly ILogger<SolicitudVacacionesController> _logger;
|
|||
|
|
|
|||
|
|
public SolicitudVacacionesController(ISolicitudVacacionesRepo SolicitudVacacionesRepo, IMapper mapper, ILogger<SolicitudVacacionesController> logger)
|
|||
|
|
{
|
|||
|
|
_SolicitudVacacionesRepo = SolicitudVacacionesRepo;
|
|||
|
|
_mapper = mapper;
|
|||
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpGet]
|
|||
|
|
public async Task<IEnumerable<SolicitudVacacionesDto>> GetSolicitudes()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var solicitudVacaciones = await _SolicitudVacacionesRepo.GetSolicitudes();
|
|||
|
|
|
|||
|
|
var solicitudVacacionesDto = _mapper.Map<IEnumerable<SolicitudVacacionesDto>>(solicitudVacaciones);
|
|||
|
|
|
|||
|
|
return solicitudVacacionesDto;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
var solicitudVacacionesDto = new List<SolicitudVacacionesDto>
|
|||
|
|
{
|
|||
|
|
new SolicitudVacacionesDto() { CodResultado = 500, Mensaje = "Error" }
|
|||
|
|
};
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return solicitudVacacionesDto;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//[Route("ObtenerTodos/{id}")]
|
|||
|
|
//[HttpGet]
|
|||
|
|
//public async Task<IEnumerable<SolicitudVacacionesDto>> GetSolicitudesId(int id)
|
|||
|
|
//{
|
|||
|
|
// try
|
|||
|
|
// {
|
|||
|
|
// var solicitudVacaciones = await _SolicitudVacacionesRepo.GetSolicitudesId(id);
|
|||
|
|
|
|||
|
|
// var solicitudVacacionesDto = _mapper.Map<IEnumerable<SolicitudVacacionesDto>>(solicitudVacaciones);
|
|||
|
|
|
|||
|
|
// return solicitudVacacionesDto;
|
|||
|
|
// }
|
|||
|
|
// catch (Exception ex)
|
|||
|
|
// {
|
|||
|
|
// var solicitudVacacionesDto = new List<SolicitudVacacionesDto>
|
|||
|
|
// {
|
|||
|
|
// new SolicitudVacacionesDto() { CodResultado = 500, Mensaje = "Error" }
|
|||
|
|
// };
|
|||
|
|
// _logger.LogError(ex, ex.Message);
|
|||
|
|
// return solicitudVacacionesDto;
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
[HttpGet("{id}/{idUsuario}")]
|
|||
|
|
public async Task<SolicitudVacacionesDto> GetSolicitud(int id, int idUsuario)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var solicitud = await _SolicitudVacacionesRepo.GetSolicitud(id, idUsuario);
|
|||
|
|
|
|||
|
|
var solicitudDto = _mapper.Map<SolicitudVacacionesDto>(solicitud);
|
|||
|
|
|
|||
|
|
return solicitudDto;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
var solicitudDto = new SolicitudVacacionesDto
|
|||
|
|
{
|
|||
|
|
CodResultado = 500,
|
|||
|
|
Mensaje = "Error"
|
|||
|
|
};
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return solicitudDto;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Route("Aprobar/{id}")]
|
|||
|
|
[HttpPut]
|
|||
|
|
public async Task<IActionResult> AprobarSolicitud(int id, SolicitudVacacionesDto solicitudVacacionesDto)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var solicitud = _mapper.Map<SolicitudVacaciones>(solicitudVacacionesDto);
|
|||
|
|
solicitudVacacionesDto.IdSolicitud = id;
|
|||
|
|
|
|||
|
|
var resultado = await _SolicitudVacacionesRepo.AprobarSolicitud(solicitud);
|
|||
|
|
|
|||
|
|
return Ok(resultado);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return StatusCode(500);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Route("Denegar/{id}")]
|
|||
|
|
[HttpPut]
|
|||
|
|
public async Task<IActionResult> DenegarSolicitud(int id, SolicitudVacacionesDto solicitudVacacionesDto)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var solicitud = _mapper.Map<SolicitudVacaciones>(solicitudVacacionesDto);
|
|||
|
|
solicitudVacacionesDto.IdSolicitud = id;
|
|||
|
|
|
|||
|
|
var resultado = await _SolicitudVacacionesRepo.DenegarSolicitud(solicitud);
|
|||
|
|
|
|||
|
|
return Ok(resultado);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return StatusCode(500);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost]
|
|||
|
|
public async Task<IActionResult> PostSolicitud(SolicitudVacacionesDto solicitudVacacionesDto)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var solicitud = _mapper.Map<SolicitudVacaciones>(solicitudVacacionesDto);
|
|||
|
|
await _SolicitudVacacionesRepo.PostSolicitud(solicitud);
|
|||
|
|
|
|||
|
|
return Ok(new RespuestaDTO() { Resultado = "Se realizaron los cambios satisfactoriamente" });
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return StatusCode(500);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Route("Anular/{id}")]
|
|||
|
|
[HttpPut]
|
|||
|
|
public async Task<IActionResult> AnularSolicitud(int id, SolicitudVacacionesDto solicitudVacacionesDto)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var solicitud = _mapper.Map<SolicitudVacaciones>(solicitudVacacionesDto);
|
|||
|
|
solicitudVacacionesDto.IdSolicitud = id;
|
|||
|
|
|
|||
|
|
var resultado = await _SolicitudVacacionesRepo.AnularSolicitud(solicitud);
|
|||
|
|
|
|||
|
|
return Ok(resultado);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_logger.LogError(ex, ex.Message);
|
|||
|
|
return StatusCode(500);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|