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