Task ICandidatoService.AddCandidatoToTernaAsync(int idRequisicion, int idCandidato, ETerna idTerna) { throw new NotImplementedException(); }
public async Task AddCandidatoToTernaAsync(int idRequisicion, int idCandidato, ETerna idTerna) { var ternas = await this.ternasRepository.ListAsync(new TernasSpecification(idRequisicion)) .ConfigureAwait(false); var ternaDestino = ternas.FirstOrDefault(t => t?.TipoTerna == idTerna); TernaCandidato ternaCandidato = null; foreach (var terna in ternas) { ternaCandidato = terna.TernaCandidato.FirstOrDefault(tc => tc.Id == idCandidato); if (ternaCandidato == null) { continue; } ternaCandidato.Ternas = ternaDestino; ternaCandidato.EstadoCandidato = EEstadoCandidato.NoCalificado; break; } if (ternaDestino == null) { var requisicion = await this.requisicionRepository.Single(new RequisicionSpecification(idRequisicion)); ternaDestino = new Ternas { RequisicionDetalleId = requisicion.RequisicionDetalle.Id, TipoTerna = idTerna }; await this.ternasRepository.AddAsync(ternaDestino); } if (ternaCandidato != null) { if (ternaDestino.TernaCandidato == null) { ternaDestino.TernaCandidato = new List <TernaCandidato>(); } ternaDestino.TernaCandidato.Add(ternaCandidato); await this.ternasRepository.UpdateAsync(ternaDestino) .ConfigureAwait(false); } await this.AlertarSeguimiento(idRequisicion) .ConfigureAwait(false); }