From 7b7546bc19224fd9c8df5e20bb6850ba7625b254 Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Wed, 3 Feb 2021 08:57:28 +0100 Subject: [PATCH] Ajout de la liste des participations sans les collaborateurs ni les EP --- EPAServeur/Services/FormationService.cs | 79 +++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/EPAServeur/Services/FormationService.cs b/EPAServeur/Services/FormationService.cs index 1ef4934..2c25d60 100644 --- a/EPAServeur/Services/FormationService.cs +++ b/EPAServeur/Services/FormationService.cs @@ -73,6 +73,9 @@ namespace EPAServeur.Services .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) + .Include(formation => formation.ParticipationsFormation) + .ThenInclude(participation => participation.DemandeFormation) + .ThenInclude(demande => demande.Ep) .FirstOrDefaultAsync(formation => formation.IdFormation == idFormation); if (formation == null) @@ -91,17 +94,18 @@ namespace EPAServeur.Services /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// - public async Task> GetFormationsAsync(long? idAgence, List idStatuts, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) + public async Task> GetFormationsAsync(long? idAgence, List idStatuts, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { IQueryable query; IEnumerable formations; - IEnumerable formationDTOs; + IEnumerable formationDTOs; query = epContext.Formation .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) - .Include(formation => formation.TypeFormation); + .Include(formation => formation.TypeFormation) + .Include(formation => formation.ParticipationsFormation); query = IdStatutsFilter(query, idStatuts); @@ -117,7 +121,7 @@ namespace EPAServeur.Services formations = await query.ToListAsync(); - formationDTOs = formations.Select(formation => GetFormationDTO(formation)); + formationDTOs = formations.Select(formation => GetFormationDetailsDTO(formation)); return formationDTOs; } @@ -140,7 +144,8 @@ namespace EPAServeur.Services .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) - .Include(formation => formation.TypeFormation); + .Include(formation => formation.TypeFormation) + .Include(formation => formation.ParticipationsFormation); query = IntituleFilter(query, texte); @@ -517,7 +522,31 @@ namespace EPAServeur.Services Origine = GetOrigineFormationDTO(formation.Origine), Statut = GetStatutFormationDTO(formation.Statut), Mode = GetModeFormationDTO(formation.ModeFormation), - Type = GetTypeFormationDTO(formation.TypeFormation) + Type = GetTypeFormationDTO(formation.TypeFormation), + Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation) + }; + + return formationDTO; + } + + /// + /// Récuperer un objet FormationDetailsDTO en fonction d'un objet Formation + /// + /// + /// + private FormationDetailsDTO GetFormationDetailsDTO(Formation formation) + { + FormationDetailsDTO formationDTO = new FormationDetailsDTO() + { + Id = formation.IdFormation, + Intitule = formation.Intitule, + DateDebut = formation.DateDebut, + DateFin = formation.DateFin, + Organisme = formation.Organisme, + EstCertifiee = formation.EstCertifiee, + NbParticipations = formation.ParticipationsFormation.Count, + Origine = GetOrigineFormationDTO(formation.Origine), + Statut = GetStatutFormationDTO(formation.Statut), }; return formationDTO; @@ -573,6 +602,7 @@ namespace EPAServeur.Services }; return modeFormationDTO; } + /// /// Récuperer un objet TypeFormationDTO en fonction d'un objet TypeFormation /// @@ -590,6 +620,43 @@ namespace EPAServeur.Services return typeFormationDTO; } + /// + /// Récuperer une liste de ParticipationFormationDTO en fonction d'une liste de ParticipationFormation + /// + /// + /// + private List GetParticipationsFormationDTO(List participationsFormation) + { + List participationFormationDTOs; + + if (participationsFormation == null || participationsFormation.Count == 0) + return null; + + participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation)).ToList(); + + return participationFormationDTOs; + } + + /// + /// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation + /// + /// + /// + private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation) + { + if (participationFormation == null) + return null; + ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO() + { + Id = participationFormation.IdParticipationFormation, + DateCreation = participationFormation.DateCreation, + Intitule = participationFormation.Formation.Intitule, + DateDebut= participationFormation.Formation.DateDebut, + Statut = GetStatutFormationDTO(participationFormation.Formation.Statut), + }; + return participationFormationDTO; + } + #endregion #region DTO to Object