|
|
|
@ -1,7 +1,12 @@ |
|
|
|
|
using EPAServeur.Context; |
|
|
|
|
using EPAServeur.Exceptions; |
|
|
|
|
using EPAServeur.IServices; |
|
|
|
|
using EPAServeur.Models.EP; |
|
|
|
|
using IO.Swagger.ApiCollaborateur; |
|
|
|
|
using IO.Swagger.DTO; |
|
|
|
|
using IO.Swagger.Enum; |
|
|
|
|
using IO.Swagger.ModelCollaborateur; |
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
@ -12,8 +17,8 @@ namespace EPAServeur.Services |
|
|
|
|
public class DemandeDelegationService : IDemandeDelegationService |
|
|
|
|
{ |
|
|
|
|
#region variables |
|
|
|
|
private EpContext context; |
|
|
|
|
private ICollaborateurApi collaborateurAPI; |
|
|
|
|
private readonly EpContext context; |
|
|
|
|
private static ICollaborateurApi collaborateurAPI; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region constructeur |
|
|
|
@ -24,10 +29,23 @@ namespace EPAServeur.Services |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region services async |
|
|
|
|
public async Task<IEnumerable<DemandeDelegationDTO>> RecupererDemandesDelegation(Guid? idReferent) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
Collaborateur referent = await collaborateurAPI.ChercherCollabIdAsync(idReferent); |
|
|
|
|
if (referent == null) |
|
|
|
|
throw new ReferentNotFoundException(); |
|
|
|
|
|
|
|
|
|
CollaborateurDTO referentDTO = GetCollaborateurDTO(referent); |
|
|
|
|
//var tasks = context.DemandeDelegations.Where( d => d.IdReferent.Equals(idReferent) && d.EtatDemande.Equals(EtatDemande.EnAttente)).Select() |
|
|
|
|
|
|
|
|
|
var tasks = from demandeDelegation in context.DemandeDelegations.Include( d => d.Ep) |
|
|
|
|
where demandeDelegation.IdReferent.Equals(idReferent) && demandeDelegation.EtatDemande.Equals(EtatDemande.EnAttente) |
|
|
|
|
select GetDemandeDelegationDTO(demandeDelegation, referentDTO) ; |
|
|
|
|
|
|
|
|
|
return await Task.WhenAll(tasks); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<DemandeDelegationDTO> UpdateDemandeDelegation(long id, DemandeDelegationDTO demandeDelegationDTO) |
|
|
|
@ -35,5 +53,47 @@ namespace EPAServeur.Services |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region |
|
|
|
|
private static CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur) |
|
|
|
|
{ |
|
|
|
|
return new CollaborateurDTO() |
|
|
|
|
{ |
|
|
|
|
Id = collaborateur.Id, |
|
|
|
|
Nom = collaborateur.Nom, |
|
|
|
|
Prenom = collaborateur.Prenom, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static async Task<EpInformationDTO> GetEpInformationDTO(Ep ep) |
|
|
|
|
{ |
|
|
|
|
return new EpInformationDTO() |
|
|
|
|
{ |
|
|
|
|
Id = ep.IdEP, |
|
|
|
|
Collaborateur = GetCollaborateurDTO(await collaborateurAPI.ChercherCollabIdAsync(ep.IdCollaborateur)), |
|
|
|
|
DatePrevisionnelle = ep.DatePrevisionnelle, |
|
|
|
|
Statut = ep.Statut, |
|
|
|
|
Type = ep.TypeEP, |
|
|
|
|
Obligatoire = ep.Obligatoire, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static async Task<DemandeDelegationDTO> GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent ) |
|
|
|
|
{ |
|
|
|
|
return new DemandeDelegationDTO() |
|
|
|
|
{ |
|
|
|
|
Id = demande.IdDemandeDelegation, |
|
|
|
|
DateDemande = demande.DateDemande, |
|
|
|
|
EtatDemande = demande.EtatDemande, |
|
|
|
|
Referent = referent, |
|
|
|
|
RaisonDemande = demande.RaisonDemande, |
|
|
|
|
Ep = await GetEpInformationDTO( demande.Ep) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|