diff --git a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs index 2621269..0058240 100644 --- a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs +++ b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs @@ -148,6 +148,24 @@ namespace EPAServeur.Tests.Services } #endregion + #region Récupérer EP avec demandes de délégation + [TestCase(1, false)] + [TestCase(2, true)] + [TestCase(4, true)] + [TestCase(8, true)] + [TestCase(9, false)] + [TestCase(12, false)] + public async Task GetEpById_GetDemandeDelegation(long idEp, bool possedeDemandeDelegation) + { + IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); + EpDTO epDTO = await epDetailsService.GetEp(idEp); + if(possedeDemandeDelegation) + Assert.IsNotNull(epDTO.DemandesDelegation); + else + Assert.IsNull(epDTO.DemandesDelegation); + } + #endregion + #region Récupérer EP avec RDV entretiens #endregion @@ -155,8 +173,6 @@ namespace EPAServeur.Tests.Services #endregion - #region Récupérer EP avec demandes de délégation - #endregion #region Récupérer EP avec demandes de formation #endregion diff --git a/EPAServeur/Context/DataSeeder.cs b/EPAServeur/Context/DataSeeder.cs index ba32f35..d957ce7 100644 --- a/EPAServeur/Context/DataSeeder.cs +++ b/EPAServeur/Context/DataSeeder.cs @@ -87,6 +87,7 @@ namespace EPAServeur.Context Engagement eg1, eg2, eg3, eg4; ParticipationEP p1, p2, p3, p4, p5; CommentaireAssistant ca1, ca2, ca3; + DemandeDelegation dm1, dm2, dm3; //Ep en cours Ep epEnCours1, epEnCours2, epEnCours3, epEnCours4, epEnCours5, epEnCours6, epEnCours7, epEnCours8, epEnCours9; @@ -131,6 +132,15 @@ namespace EPAServeur.Context Ep = epEnCours2 }; epEnCours2.CommentairesAssistant = new List(new[] { ca1, ca2 }); + dm1 = new DemandeDelegation() + { + DateDemande = DateTime.Now, + Ep = epEnCours1, + IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), + EtatDemande = EtatDemande.EnAttente, + RaisonDemande = "Raison quelconque 1" + }; + epEnCours2.DemandeDelegation = dm1; epContext.Ep.Add(epEnCours2); @@ -175,6 +185,15 @@ namespace EPAServeur.Context IdCollaborateur = new Guid("a0f40e2a-cc03-4032-a627-5389e1281c64"), Obligatoire = false, }; + dm2 = new DemandeDelegation() + { + DateDemande = DateTime.Now, + Ep = epEnCours4, + IdReferent = new Guid("d4fc247b-015a-44d6-8f3e-a52f0902d2bf"), + EtatDemande = EtatDemande.EnAttente, + RaisonDemande = "Raison quelconque 2" + }; + epEnCours4.DemandeDelegation = dm2; epContext.Ep.Add(epEnCours4); epEnCours5 = new Ep() @@ -270,6 +289,15 @@ namespace EPAServeur.Context Obligatoire = true, }; epContext.Ep.Add(epEnCours8); + dm3 = new DemandeDelegation() + { + DateDemande = DateTime.Now, + Ep = epEnCours8, + IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), + EtatDemande = EtatDemande.EnAttente, + RaisonDemande = "Raison quelconque 3" + }; + epEnCours8.DemandeDelegation = dm3; epEnCours9 = new Ep() { @@ -422,7 +450,7 @@ namespace EPAServeur.Context epSigne7.CommentairesAssistant = new List(); epSigne7.CommentairesAssistant.Add(ca3); epContext.Ep.Add(epSigne7); - + epSigne8 = new Ep() { DateDisponibilite = new DateTime(2020, 2, 13), diff --git a/EPAServeur/DTO/EpDTO.cs b/EPAServeur/DTO/EpDTO.cs index 8d7c904..9ab13b3 100644 --- a/EPAServeur/DTO/EpDTO.cs +++ b/EPAServeur/DTO/EpDTO.cs @@ -173,7 +173,7 @@ namespace IO.Swagger.DTO /// Gets or Sets DemandesDelegation /// [DataMember(Name="demandesDelegation")] - public List DemandesDelegation { get; set; } + public DemandeDelegationDTO DemandesDelegation { get; set; } /// /// Gets or Sets DemandeEPI @@ -371,7 +371,7 @@ namespace IO.Swagger.DTO ( DemandesDelegation == other.DemandesDelegation || DemandesDelegation != null && - DemandesDelegation.SequenceEqual(other.DemandesDelegation) + DemandesDelegation.Equals(other.DemandesDelegation) ) && ( DemandeEPI == other.DemandeEPI || diff --git a/EPAServeur/IServices/ITransformDTO.cs b/EPAServeur/IServices/ITransformDTO.cs index ed7dffe..3b6e841 100644 --- a/EPAServeur/IServices/ITransformDTO.cs +++ b/EPAServeur/IServices/ITransformDTO.cs @@ -75,9 +75,9 @@ namespace EPAServeur.IServices List GetEngagementDTOs(List engagements); List GetParticipantsDTO(List participants, IEnumerable collaborateurDTOs); List GetCommentaireAssistant(List commentaireAssistant, IEnumerable collaborateurDTOs); + DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable collaborateurDTOs); DemandeEPIDTO GetDemandeEPIDTO(DemandeEPI demande, IEnumerable collaborateurDTOs); AugmentationSalaireDTO GetAugmentationSalaireDTO(AugmentationSalaire augmentation); - DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable collaborateurDTOs); RDVEntretienDTO GetRDVEntretienDTO(RdvEntretien rdvEntretien); TypeEntretienDTO GetEntretienDTO(ChoixTypeEntretien choixTypeEntretien); DemandeFormationDTO GetDemandeFormationDTOEP(DemandeFormation demandeFormation); diff --git a/EPAServeur/Services/EpDetailsService.cs b/EPAServeur/Services/EpDetailsService.cs index 18c9efa..e49b8f4 100644 --- a/EPAServeur/Services/EpDetailsService.cs +++ b/EPAServeur/Services/EpDetailsService.cs @@ -30,6 +30,7 @@ namespace EPAServeur.Services .Include(ep => ep.Engagements) .Include(ep => ep.Participants) .Include(ep => ep.CommentairesAssistant) + .Include(ep => ep.DemandeDelegation) .FirstOrDefaultAsync(ep => ep.IdEP.Equals(id)); if (ep == null) throw new EpNotFoundException(); @@ -43,7 +44,8 @@ namespace EPAServeur.Services guids.AddRange(ep.Participants.SelectMany(p => new[] { (Guid?)p.IdParticipant })); if (ep.CommentairesAssistant != null && ep.CommentairesAssistant.Any()) guids.AddRange(ep.CommentairesAssistant.SelectMany(p => new[] { (Guid?)p.IdAssistant })); - + if (ep.DemandeDelegation != null) + guids.Add(ep.DemandeDelegation.IdReferent); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); diff --git a/EPAServeur/Services/TransformDTO.cs b/EPAServeur/Services/TransformDTO.cs index 3f43355..9d4be93 100644 --- a/EPAServeur/Services/TransformDTO.cs +++ b/EPAServeur/Services/TransformDTO.cs @@ -63,7 +63,8 @@ namespace EPAServeur.Services Cv = ep.CV, Engagements = GetEngagementDTOs(ep.Engagements), Participants = GetParticipantsDTO(ep.Participants, collaborateurDTOs), - CommentairesAssistant = GetCommentaireAssistant(ep.CommentairesAssistant, collaborateurDTOs) + CommentairesAssistant = GetCommentaireAssistant(ep.CommentairesAssistant, collaborateurDTOs), + DemandesDelegation = GetDemandeDelegationDTO(ep.DemandeDelegation, collaborateurDTOs), }; } @@ -260,7 +261,19 @@ namespace EPAServeur.Services /// La demande de délégation transformé en DTO public DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable collaborateurDTOs) { - throw new NotImplementedException(); + if (demandeDelegation == null) + return null; + DemandeDelegationDTO demandeDelegationDTO = new DemandeDelegationDTO() + { + DateDemande = demandeDelegation.DateDemande, + DateReponse = demandeDelegation.DateReponse, + EtatDemande = demandeDelegation.EtatDemande, + Id = demandeDelegation.IdDemandeDelegation, + RaisonDemande = demandeDelegation.RaisonDemande, + RaisonRefus = demandeDelegation.RaisonRefus, + Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(demandeDelegation.IdReferent)) + }; + return demandeDelegationDTO.Referent != null ? demandeDelegationDTO : null; } /// @@ -577,9 +590,7 @@ namespace EPAServeur.Services }); } } - if (participantsDTO.Any()) - return participantsDTO; - return null; + return participantsDTO.Any() ? participantsDTO : null; } ///