diff --git a/Controllers/Corresponsalias/AnticiposController.cs b/Controllers/Corresponsalias/AnticiposController.cs index 86a6b3c..76d4af4 100644 --- a/Controllers/Corresponsalias/AnticiposController.cs +++ b/Controllers/Corresponsalias/AnticiposController.cs @@ -4,6 +4,7 @@ using CORRESPONSALBackend.DTO.Corresponsales; using CORRESPONSALBackend.Models.Corresponsales; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; +using CORRESPONSALBackend.Contracts.Utils; namespace CORRESPONSALBackend.Controllers.Corresponsalias { @@ -15,11 +16,13 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias { private readonly ICorresponsaliasAnticiposRepository _Repo; private readonly IConfiguration _config; + private readonly IFileManagerRepository _fileManager; - public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config) + public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config, IFileManagerRepository fileManager) { _config = config; _Repo = Repo; + _fileManager = fileManager; } [HttpPost] @@ -35,6 +38,16 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias public async Task> GetAll([FromQuery] int IdTrafico) { var entrada = await _Repo.getAll(IdTrafico); + var sinAutorizar = entrada.Where(x => x.Autoriza == 0).ToList(); + if(sinAutorizar.Count > 0){ + foreach (var anticipo in sinAutorizar){ + var comprobanteAnticipo = await _fileManager.getFileByProcess(anticipo.id, 4); + if(comprobanteAnticipo.Tags != ""){ + await Autoriza(new DTOCorresponsalesAnticipo(){id= anticipo.id, IdUsuario = comprobanteAnticipo.IdUsuario}); + } + } + return await _Repo.getAll(IdTrafico); + } return entrada; }