|
|
|
@ -18,8 +18,7 @@ namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
|
#region variables |
|
|
|
|
private readonly EpContext context; |
|
|
|
|
private static ICollaborateurApi collaborateurAPI; |
|
|
|
|
private static ICollaborateurService collaborateurService; |
|
|
|
|
private readonly ICollaborateurService collaborateurService; |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
@ -35,22 +34,19 @@ namespace EPAServeur.Services |
|
|
|
|
#region services async |
|
|
|
|
public async Task<IEnumerable<DemandeDelegationDTO>> RecupererDemandesDelegation(Guid? idReferent) |
|
|
|
|
{ |
|
|
|
|
CollaborateurDTO referentDTO; |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
referentDTO = await collaborateurService.GetCollaborateurByIdAsync(idReferent); |
|
|
|
|
} |
|
|
|
|
catch(CollaborateurNotFoundException) |
|
|
|
|
IEnumerable<DemandeDelegation> demandesDelegation = context.DemandeDelegation.Include(d => d.Ep).Where(d => d.IdReferent.Equals(idReferent) && d.EtatDemande.Equals(EtatDemande.EnAttente)); |
|
|
|
|
|
|
|
|
|
List<Guid?> guids = demandesDelegation.SelectMany(demande => new[] { (Guid?)demande.Ep.IdCollaborateur, demande.Ep.IdReferent }).ToList(); |
|
|
|
|
guids.Add(idReferent); |
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateursDTO = await collaborateurService.GetCollaborateurDTOsAsync(guids); |
|
|
|
|
|
|
|
|
|
CollaborateurDTO referent = collaborateursDTO.FirstOrDefault(c => c.Id.Equals(idReferent)); |
|
|
|
|
if(referent == null) |
|
|
|
|
{ |
|
|
|
|
throw new ReferentNotFoundException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tasks = from demandeDelegation in context.DemandeDelegation.Include( d => d.Ep) |
|
|
|
|
where demandeDelegation.IdReferent.Equals(idReferent) && demandeDelegation.EtatDemande.Equals(EtatDemande.EnAttente) |
|
|
|
|
select GetDemandeDelegationDTO(demandeDelegation, referentDTO) ; |
|
|
|
|
|
|
|
|
|
return await Task.WhenAll(tasks); |
|
|
|
|
return demandesDelegation.Select(d => GetDemandeDelegationDTO(d, referent, collaborateursDTO)); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -107,13 +103,13 @@ namespace EPAServeur.Services |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task<EpInformationDTO> GetEpInformationDTO(Ep ep) |
|
|
|
|
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurs) |
|
|
|
|
{ |
|
|
|
|
return new EpInformationDTO() |
|
|
|
|
{ |
|
|
|
|
Id = ep.IdEP, |
|
|
|
|
Collaborateur = await collaborateurService.GetCollaborateurByIdAsync(ep.IdCollaborateur), |
|
|
|
|
Referent = await collaborateurService.GetCollaborateurByIdAsync(ep.IdReferent), |
|
|
|
|
Collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)), |
|
|
|
|
Referent = collaborateurs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)), |
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle, |
|
|
|
|
DateDisponibilite = ep.DateDisponibilite, |
|
|
|
|
Statut = ep.Statut, |
|
|
|
@ -122,7 +118,7 @@ namespace EPAServeur.Services |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static async Task<DemandeDelegationDTO> GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent ) |
|
|
|
|
private DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable<CollaborateurDTO> collaborateurs) |
|
|
|
|
{ |
|
|
|
|
return new DemandeDelegationDTO() |
|
|
|
|
{ |
|
|
|
@ -131,7 +127,7 @@ namespace EPAServeur.Services |
|
|
|
|
EtatDemande = demande.EtatDemande, |
|
|
|
|
Referent = referent, |
|
|
|
|
RaisonDemande = demande.RaisonDemande, |
|
|
|
|
Ep = await GetEpInformationDTO( demande.Ep) |
|
|
|
|
Ep = GetEpInformationDTO(demande.Ep, collaborateurs) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|