diff --git a/EPAServeur/Services/CollaborateurService.cs b/EPAServeur/Services/CollaborateurService.cs index 1837b35..942747c 100644 --- a/EPAServeur/Services/CollaborateurService.cs +++ b/EPAServeur/Services/CollaborateurService.cs @@ -2,6 +2,7 @@ using EPAServeur.Exceptions; using EPAServeur.IServices; using EPAServeur.Models.EP; +using EPAServeur.Models.Formation; using IO.Swagger.ApiCollaborateur; using IO.Swagger.DTO; using IO.Swagger.ModelCollaborateur; @@ -26,6 +27,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurApi collaborateurApi; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + /// /// Nombre d'éléments min à afficher par page /// @@ -49,10 +55,11 @@ namespace EPAServeur.Services #region Constructeurs - public CollaborateurService(ICollaborateurApi _collaborateurApi, EpContext _contexte) + public CollaborateurService(ICollaborateurApi _collaborateurApi, EpContext _contexte, ITransformDTO _transformDTO) { collaborateurApi = _collaborateurApi; context = _contexte; + transformDTO = _transformDTO; } #endregion @@ -259,6 +266,125 @@ namespace EPAServeur.Services return collaborateursDTO; } + /// + /// Transformer un collaborateur en collaborateurDTO de manière asynchrone. + /// + /// Collaborateur à transformer en collaborateurDTO + /// Indiquer si le référent du collaborateur doit être récupéré ou non + /// Renvoie la transformation DTO du collaborateur + public async Task GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent) + { + CollaborateurDTO collaborateurDTO = new CollaborateurDTO() + { + Id = collaborateur.Id, + Prenom = collaborateur.Prenom, + Nom = collaborateur.Nom, + MailApside = collaborateur.MailApside, + DateArrivee = collaborateur.DateArrivee, + + }; + collaborateurDTO.BusinessUnit = transformDTO.GetBusinessUnitDTO(collaborateur.BusinessUnit); + //Si le référent du collaborateur doit être récupérer en même temps + if (chercherReferent) + collaborateurDTO.Referent = await GetReferentAsync(collaborateurDTO); + return collaborateurDTO; + } + + /// + /// Récupérer une liste de CollaborateurDTO contenant les collaborateurs et les référents. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(List participationsFormation) + { + if (participationsFormation == null || participationsFormation.Count == 0) + return null; + + List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer une liste de CollaborateurDTO contenant les collaborateurs et les référents. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(IEnumerable participationsFormation) + { + if (participationsFormation == null || !participationsFormation.Any()) + return null; + + List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + + /// + /// Récupérer le collaborateur et le référent qui sont présent dans l'EP qui est lié à l'engagement. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(Engagement engagement) + { + if (engagement == null) + return null; + + List guids = new List(); + + guids.Add((Guid?)engagement.Ep.IdCollaborateur); + guids.Add(engagement.Ep.IdReferent); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer les collaborateurs et les référents qui sont présent dans les EP qui sont liés aux engagements. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(IEnumerable engagements) + { + if (engagements == null || !engagements.Any()) + return null; + + List guids = engagements.SelectMany(engagement => new[] { (Guid?)engagement.Ep.IdCollaborateur, engagement.Ep.IdReferent }).ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer le collaborateur et le référent qui sont présent dans les EP. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(IEnumerable eps) + { + if (eps == null || !eps.Any()) + return null; + + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer le référent EP d'un collaborateur de manière asynchrone s'il existe. + /// + /// Le collaborateur dont on cherche le référent EP + /// Le référent EP du collaborateur + public async Task GetReferentAsync(CollaborateurDTO collaborateur) + { + ReferentEP referentEP = await context.ReferentEP.FindAsync(collaborateur.Id); + //vérifier que le collaorateur a un référent EP + if (referentEP == null || referentEP.IdReferent == null || !referentEP.IdReferent.HasValue || referentEP.IdReferent.Value == null) + return null; + Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(referentEP.IdReferent); + if (referent == null) + return null; + return await GetCollaborateurDTOAsync(referent, false); + } #endregion @@ -337,93 +463,5 @@ namespace EPAServeur.Services } #endregion - - #region DTO To Object - - /// - /// Transformer une agence en agenceDTO - /// - /// agence à transformer en agenceDTO - /// Retourne la transformation DTO de l'agence - private AgenceDTO GetAgenceDTO(Agence agence) - { - if (agence == null) - return null; - AgenceDTO agenceDTO = new AgenceDTO() - { - Id = agence.Id, - Nom = agence.Nom, - Bu = new List() - }; - agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO() - { - Id = bu.Id, - Nom = bu.Nom - }).ToList(); - return agenceDTO; - } - - /// - /// Transforme une businessUnit en businessUnitDTO - /// - /// businessUnit à transformer en businessUnitDTO - /// Retourne la transformation DTO de la businessUnit - private BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit) - { - if (businessUnit == null) - return null; - BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO() - { - Id = businessUnit.Id, - Nom = businessUnit.Nom, - Agence = GetAgenceDTO(businessUnit.Agence) - }; - return businessUnitDTO; - } - - - /// - /// Transforme un collaborateur en collaborateurDTO de manière asynchrone - /// - /// collaborateur à transformer en collaborateurDTO - /// Indiquer si le référent du collaborateur doit être récupéré ou non - /// Renvoie la transformation DTO du collaborateur - private async Task GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent) - { - CollaborateurDTO collaborateurDTO = new CollaborateurDTO() - { - Id = collaborateur.Id, - Prenom = collaborateur.Prenom, - Nom = collaborateur.Nom, - MailApside = collaborateur.MailApside, - DateArrivee = collaborateur.DateArrivee, - - }; - collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit); - //Si le référent du collaborateur doit être récupérer en même temps - if (chercherReferent) - collaborateurDTO.Referent = await GetReferentAsync(collaborateurDTO); - return collaborateurDTO; - } - - - - /// - /// Récupérer le référent EP d'un collaborateur de manière asynchrone si il existe - /// - /// Le collaborateur dont on cherche le référent EP - /// Le référent EP du collaborateur - private async Task GetReferentAsync(CollaborateurDTO collaborateur) - { - ReferentEP referentEP = await context.ReferentEP.FindAsync(collaborateur.Id); - //vérifier que le collaorateur a un référent EP - if (referentEP == null || referentEP.IdReferent == null || !referentEP.IdReferent.HasValue || referentEP.IdReferent.Value == null) - return null; - Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(referentEP.IdReferent); - if (referent == null) - return null; - return await GetCollaborateurDTOAsync(referent, false); - } - #endregion } } diff --git a/EPAServeur/Services/DemandeDelegationService.cs b/EPAServeur/Services/DemandeDelegationService.cs index 48347e5..1ceb7de 100644 --- a/EPAServeur/Services/DemandeDelegationService.cs +++ b/EPAServeur/Services/DemandeDelegationService.cs @@ -17,16 +17,29 @@ namespace EPAServeur.Services public class DemandeDelegationService : IDemandeDelegationService { #region variables + /// + /// Accès et gestion de la base de données + /// private readonly EpContext context; + + /// + /// Accès et service collaborateur + /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + #endregion #region constructeur - public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context) + public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context, ITransformDTO _transformDTO) { context = _context; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -46,7 +59,7 @@ namespace EPAServeur.Services throw new ReferentNotFoundException(); } - return demandesDelegation.Select(d => GetDemandeDelegationDTO(d, referent, collaborateursDTO)); + return demandesDelegation.Select(d => transformDTO.GetDemandeDelegationDTO(d, referent, collaborateursDTO)); } @@ -102,36 +115,6 @@ namespace EPAServeur.Services return demandeDelegationDTO; } - - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurs) - { - return new EpInformationDTO() - { - Id = ep.IdEP, - 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, - Type = ep.TypeEP, - Obligatoire = ep.Obligatoire, - }; - } - - private DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable collaborateurs) - { - return new DemandeDelegationDTO() - { - Id = demande.IdDemandeDelegation, - DateDemande = demande.DateDemande, - EtatDemande = demande.EtatDemande, - Referent = referent, - RaisonDemande = demande.RaisonDemande, - Ep = GetEpInformationDTO(demande.Ep, collaborateurs) - }; - - } - #endregion diff --git a/EPAServeur/Services/EngagementService.cs b/EPAServeur/Services/EngagementService.cs index 3b35cd7..9e0f560 100644 --- a/EPAServeur/Services/EngagementService.cs +++ b/EPAServeur/Services/EngagementService.cs @@ -27,6 +27,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + /// /// Nombre d'éléments min à afficher par page /// @@ -60,10 +65,11 @@ namespace EPAServeur.Services /// Constructeur de la classe EngagementService /// /// - public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService) + public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO) { epContext = _epContext; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -96,9 +102,9 @@ namespace EPAServeur.Services engagements = await query.ToListAsync(); - collaborateurDTOs = await GetCollaborateurDTOs(engagements); + collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagements); - engagementDTOs = engagements.Select(engagement => GetEngagementDTO(engagement, collaborateurDTOs)); + engagementDTOs = engagements.Select(engagement => transformDTO.GetEngagementDTO(engagement, collaborateurDTOs)); engagementDTOs = CollaborateurFilter(engagementDTOs, texte); return engagementDTOs; @@ -118,9 +124,9 @@ namespace EPAServeur.Services engagements = await query.ToListAsync(); - collaborateurDTOs = await GetCollaborateurDTOs(engagements); + collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagements); - engagementDTOs = engagements.Select(engagement => GetEngagementDTO(engagement, collaborateurDTOs)); + engagementDTOs = engagements.Select(engagement => transformDTO.GetEngagementDTO(engagement, collaborateurDTOs)); engagementDTOs = CollaborateurFilter(engagementDTOs, texte); count = engagementDTOs.Count(); @@ -149,13 +155,13 @@ namespace EPAServeur.Services if (engagement == null) throw new EngagementNotFoundException(); - collaborateurDTOs = await GetCollaborateurDTOs(engagement); + collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagement); - engagement = SetReponseEngagement(engagement, engagementDTO); + engagement = transformDTO.SetReponseEngagement(engagement, engagementDTO); await epContext.SaveChangesAsync(); - return GetEngagementDTO(engagement, collaborateurDTOs); + return transformDTO.GetEngagementDTO(engagement, collaborateurDTOs); } @@ -323,134 +329,6 @@ namespace EPAServeur.Services return query.Skip(skip).Take(take); } - - #region Object to DTO - - /// - /// Récupère un objet EngagementDTO en fonction d'un objet Engagement et d'une liste de CollaborateurDTO - /// - /// - /// - private EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable collaborateurDTOs) - { - if (engagement == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - EngagementDTO engagementDTO = new EngagementDTO() - { - Id = engagement.IdEngagement, - Action = engagement.Action, - DateLimite = engagement.DateLimite, - Dispositif = engagement.Dispositif, - Modalite = engagement.Modalite, - RaisonNonRealisable = engagement.RaisonNonRealisable, - EtatEngagement = engagement.EtatEngagement, - Ep = GetEpInformationDTO(engagement.Ep, collaborateurDTOs) - }; - - return engagementDTO; - } - - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null si l'engagement est null. - /// - /// - /// - private async Task> GetCollaborateurDTOs(Engagement engagement) - { - if (engagement == null) - return null; - - List guids = new List(); - - guids.Add((Guid?)engagement.Ep.IdCollaborateur); - guids.Add(engagement.Ep.IdReferent); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; - } - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucun engagement. - /// - /// - /// - private async Task> GetCollaborateurDTOs(IEnumerable engagements) - { - if (engagements == null || !engagements.Any()) - return null; - - List guids = engagements.SelectMany(engagement => new[] { (Guid?)engagement.Ep.IdCollaborateur, engagement.Ep.IdReferent }).ToList(); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); - } - - /// - /// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO - /// - /// - /// - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurDTOs) - { - CollaborateurDTO collaborateur; - CollaborateurDTO referent; - - if (ep == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur); - referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent); - - EpInformationDTO epInformationDTO = new EpInformationDTO() - { - Id = ep.IdEP, - Type = ep.TypeEP, - Statut = ep.Statut, - DateDisponibilite = ep.DateDisponibilite, - DatePrevisionnelle = ep.DatePrevisionnelle, - Obligatoire = ep.Obligatoire, - Collaborateur = collaborateur, - Referent = referent, - }; - - return epInformationDTO; - } - - #endregion - - #region DTO to Object - - /// - /// Modifie la réponse d'un objet Engagement en fonction d'un objet EngagementDTO - /// - /// - /// - /// - private Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO) - { - if (engagement == null || engagementDTO == null) - return null; - - engagement.EtatEngagement = engagementDTO.EtatEngagement; - - switch (engagement.EtatEngagement) - { - case EtatEngagement.NonRealisable: - engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; - break; - case EtatEngagement.DateLimitePassee: - engagement.RaisonNonRealisable = "La date limite pour respecter l'engagement est passée."; - break; - default: - engagement.RaisonNonRealisable = null; - break; - } - - return engagement; - } - - #endregion - #endregion } diff --git a/EPAServeur/Services/EpInformationService.cs b/EPAServeur/Services/EpInformationService.cs index 49fb819..cc41351 100644 --- a/EPAServeur/Services/EpInformationService.cs +++ b/EPAServeur/Services/EpInformationService.cs @@ -13,18 +13,43 @@ namespace EPAServeur.Services public class EpInformationService : IEpInformationService { #region Variables - private EpContext context; - private ICollaborateurService collaborateurService; - private int? minParPage = 5; - private int? maxParPage = 100; - private int? defaultParPage = 15; + /// + /// Accès et gestion de la base de données + /// + private readonly EpContext context; + + /// + /// Accès et service collaborateur + /// + private readonly ICollaborateurService collaborateurService; + + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + + /// + /// Nombre d'éléments min à afficher par page + /// + private readonly int minParPage = 5; + + /// + /// Nom d'éléments max à affichar par page + /// + private readonly int maxParPage = 100; + + /// + /// Nombre d'éléments à afficher par défaut par page + /// + private readonly int defaultParPage = 15; #endregion #region constructeur - public EpInformationService(EpContext context, ICollaborateurService collaborateurService) + public EpInformationService(EpContext context, ICollaborateurService collaborateurService, ITransformDTO _transformDTO) { this.context = context; this.collaborateurService = collaborateurService; + this.transformDTO = _transformDTO; } #endregion @@ -105,7 +130,7 @@ namespace EPAServeur.Services if (ep == null) return null; IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(new List() { ep.IdReferent, ep.IdCollaborateur }); - return EpToEpDTO(ep, collaborateurDTOs); + return transformDTO.EpToEpDTO(ep, collaborateurDTOs); } #endregion @@ -116,8 +141,8 @@ namespace EPAServeur.Services { eps = TriDate(eps, dateDebut, dateFin); - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(eps); - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(eps); + IEnumerable epDTOs = eps.Select(ep => transformDTO.EpToEpDTO(ep, collaborateurDTOs)); if (!string.IsNullOrEmpty(texte)) epDTOs = epDTOs.Where(e => TriTexte(e, texte)); @@ -135,8 +160,8 @@ namespace EPAServeur.Services eps = TriDate(eps, dateDebut, dateFin); - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(eps); - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(eps); + IEnumerable epDTOs = eps.Select(ep => transformDTO.EpToEpDTO(ep, collaborateurDTOs)); if(!string.IsNullOrEmpty(texte)) epDTOs = epDTOs.Where(e => TriTexte(e, texte)); @@ -154,22 +179,6 @@ namespace EPAServeur.Services return eps; } - - private EpInformationDTO EpToEpDTO(Ep ep, IEnumerable collaborateurDTOs) - { - return new EpInformationDTO() - { - Id = ep.IdEP, - Collaborateur = collaborateurDTOs.Where(c => c.Id.Equals(ep.IdCollaborateur)).FirstOrDefault(), - DateDisponibilite = ep.DateDisponibilite, - DatePrevisionnelle = ep.DatePrevisionnelle, - Obligatoire = ep.Obligatoire, - Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)), - Statut = ep.Statut, - Type = ep.TypeEP - }; - } - private IEnumerable TriColonne(IEnumerable epDTOs, string tri) { switch (tri) @@ -223,12 +232,6 @@ namespace EPAServeur.Services return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower()); } - private async Task> GetCollaborateurDTOs(IEnumerable eps) - { - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); - return await collaborateurService.GetCollaborateurDTOsAsync(guids); - } - #endregion } } diff --git a/EPAServeur/Services/FormationService.cs b/EPAServeur/Services/FormationService.cs index fb0b113..4790b04 100644 --- a/EPAServeur/Services/FormationService.cs +++ b/EPAServeur/Services/FormationService.cs @@ -26,6 +26,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + /// /// Nombre d'éléments min à afficher par page /// @@ -59,10 +64,11 @@ namespace EPAServeur.Services /// Constructeur de la classe FormationService /// /// - public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService) + public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO) { epContext = _epContext; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -91,12 +97,12 @@ namespace EPAServeur.Services if (formation.ParticipationsFormation.Count > 0) { - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(formation.ParticipationsFormation); - return GetFormationDTO(formation, collaborateurDTOs); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(formation.ParticipationsFormation); + return transformDTO.GetFormationDTO(formation, collaborateurDTOs); } else { - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } } @@ -137,7 +143,7 @@ namespace EPAServeur.Services formations = await query.ToListAsync(); - formationDTOs = formations.Select(formation => GetFormationDetailsDTO(formation)); + formationDTOs = formations.Select(formation => transformDTO.GetFormationDetailsDTO(formation)); return formationDTOs; } @@ -187,7 +193,7 @@ namespace EPAServeur.Services modeFormations = await epContext.ModeFormation.ToListAsync(); - modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); + modeFormationDTOs = modeFormations.Select(modeFormation => transformDTO.GetModeFormationDTO(modeFormation)); return modeFormationDTOs; } @@ -203,7 +209,7 @@ namespace EPAServeur.Services origineFormations = await epContext.OrigineFormation.ToListAsync(); - origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); + origineFormationDTOs = origineFormations.Select(origineFormation => transformDTO.GetOrigineFormationDTO(origineFormation)); return origineFormationDTOs; } @@ -219,7 +225,7 @@ namespace EPAServeur.Services statutFormations = await epContext.StatutFormation.ToListAsync(); - statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); + statutFormationDTOs = statutFormations.Select(statutFormation => transformDTO.GetStatutFormationDTO(statutFormation)); return statutFormationDTOs; } @@ -235,7 +241,7 @@ namespace EPAServeur.Services typeFormations = await epContext.TypeFormation.ToListAsync(); - typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); + typeFormationDTOs = typeFormations.Select(typeFormation => transformDTO.GetTypeFormationDTO(typeFormation)); return typeFormationDTOs; } @@ -250,7 +256,7 @@ namespace EPAServeur.Services IsFormationValide(formationDTO); Formation formation = new Formation(); - formation = SetFormation(formation, formationDTO); + formation = transformDTO.SetFormation(formation, formationDTO); epContext.StatutFormation.Attach(formation.Statut); epContext.OrigineFormation.Attach(formation.Origine); @@ -260,7 +266,7 @@ namespace EPAServeur.Services await epContext.SaveChangesAsync(); - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } /// @@ -289,10 +295,10 @@ namespace EPAServeur.Services throw new FormationNotFoundException(string.Format("Aucune formation trouvée avec l'id suivant: {0}.", idFormation)); - formation = SetFormation(formation, formationDTO); + formation = transformDTO.SetFormation(formation, formationDTO); await epContext.SaveChangesAsync(); - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } /// @@ -318,7 +324,7 @@ namespace EPAServeur.Services await epContext.SaveChangesAsync(); - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } #endregion @@ -538,385 +544,6 @@ namespace EPAServeur.Services } - #region Object to DTO - /// - /// Récuperer un objet FormationDTO en fonction d'un objet Formation - /// - /// - /// - private FormationDTO GetFormationDTO(Formation formation) - { - if (formation == null) - return null; - - FormationDTO formationDTO = new FormationDTO() - { - Id = formation.IdFormation, - Intitule = formation.Intitule, - IdAgence = formation.IdAgence, - DateDebut = formation.DateDebut, - DateFin = formation.DateFin, - Heure = formation.Heure, - Jour = formation.Jour, - Organisme = formation.Organisme, - EstCertifiee = formation.EstCertifiee, - EstRealisee = formation.EstRealisee, - Origine = GetOrigineFormationDTO(formation.Origine), - Statut = GetStatutFormationDTO(formation.Statut), - Mode = GetModeFormationDTO(formation.ModeFormation), - Type = GetTypeFormationDTO(formation.TypeFormation), - }; - - return formationDTO; - } - - /// - /// Récuperer un objet FormationDTO avec des participations en fonction d'un objet Formation et d'une liste de CollaborateurDTO - /// - /// - /// - private FormationDTO GetFormationDTO(Formation formation, IEnumerable collaborateurDTOs) - { - if (formation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - FormationDTO formationDTO = new FormationDTO() - { - Id = formation.IdFormation, - Intitule = formation.Intitule, - IdAgence = formation.IdAgence, - DateDebut = formation.DateDebut, - DateFin = formation.DateFin, - Heure = formation.Heure, - Jour = formation.Jour, - Organisme = formation.Organisme, - EstCertifiee = formation.EstCertifiee, - EstRealisee = formation.EstRealisee, - Origine = GetOrigineFormationDTO(formation.Origine), - Statut = GetStatutFormationDTO(formation.Statut), - Mode = GetModeFormationDTO(formation.ModeFormation), - Type = GetTypeFormationDTO(formation.TypeFormation), - Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation, collaborateurDTOs) - }; - - return formationDTO; - } - - /// - /// Récuperer un objet FormationDetailsDTO en fonction d'un objet Formation - /// - /// - /// - private FormationDetailsDTO GetFormationDetailsDTO(Formation formation) - { - if (formation == null) - return null; - - 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; - } - - /// - /// Récuperer un objet OrigineFormationDTO en fonction d'un objet OrigineFormation - /// - /// - /// - private OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation) - { - if (origineFormation == null) - return null; - - OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO() - { - Id = origineFormation.IdOrigineFormation, - Libelle = origineFormation.Libelle - }; - - return origineFormationDTO; - } - - /// - /// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation - /// - /// - /// - private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation) - { - if (statutFormation == null) - return null; - - StatutFormationDTO statutFormationDTO = new StatutFormationDTO() - { - Id = statutFormation.IdStatutFormation, - Libelle = statutFormation.Libelle - }; - - return statutFormationDTO; - } - - /// - /// Récuperer un objet ModeFormationDTO en fonction d'un objet ModeFormation - /// - /// - /// - private ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation) - { - if (modeFormation == null) - return null; - - ModeFormationDTO modeFormationDTO = new ModeFormationDTO() - { - Id = modeFormation.IdModeFormation, - Libelle = modeFormation.Libelle - }; - - return modeFormationDTO; - } - - /// - /// Récuperer un objet TypeFormationDTO en fonction d'un objet TypeFormation - /// - /// - /// - private TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation) - { - if (typeFormation == null) - return null; - - TypeFormationDTO typeFormationDTO = new TypeFormationDTO() - { - Id = typeFormation.IdTypeFormation, - Libelle = typeFormation.Libelle - }; - - return typeFormationDTO; - } - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation. - /// - /// - /// - private async Task> GetCollaborateurDTOs(List participationsFormation) - { - if (participationsFormation == null || participationsFormation.Count == 0) - return null; - - List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; - } - - /// - /// Récuperer une liste de ParticipationFormationDTO en fonction d'une liste de ParticipationFormation et d'une liste de CollaborateurDTO. Retourne null s'il n'y a aucune participation ou aucun collaborateur. - /// - /// - /// - private List GetParticipationsFormationDTO(List participationsFormation, IEnumerable collaborateurDTOs) - { - List participationFormationDTOs; - - if (participationsFormation == null || participationsFormation.Count == 0 || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs)) - .OrderBy(participationFormation => participationFormation.Collaborateur.Nom) - .ThenBy(participationFormation => participationFormation.Collaborateur.Prenom).ToList(); - - return participationFormationDTOs; - } - - /// - /// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - 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), - Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs), - Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs) - }; - - return participationFormationDTO; - } - - /// - /// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur); - } - - /// - /// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO - /// - /// - /// - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurDTOs) - { - CollaborateurDTO collaborateur; - CollaborateurDTO referent; - - if (ep == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur); - referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent); - - EpInformationDTO epInformationDTO = new EpInformationDTO() - { - Id = ep.IdEP, - Type = ep.TypeEP, - Statut = ep.Statut, - DateDisponibilite = ep.DateDisponibilite, - DatePrevisionnelle = ep.DatePrevisionnelle, - Obligatoire = ep.Obligatoire, - Collaborateur = collaborateur, - Referent = referent, - }; - - return epInformationDTO; - } - - - #endregion - - #region DTO to Object - - /// - /// Modifier un objet Formation en fonction d'un objet FormationDTO - /// - /// - /// - /// - private Formation SetFormation(Formation formation, FormationDTO formationDTO) - { - if (formation == null || formationDTO == null) - return null; - - formation.Intitule = formationDTO.Intitule; - formation.IdAgence = formationDTO.IdAgence.Value; - formation.DateDebut = formationDTO.DateDebut.Value; - formation.DateFin = formationDTO.DateFin.Value; - formation.Heure = Convert.ToInt32(formationDTO.Heure.Value); - formation.Jour = Convert.ToInt32(formationDTO.Jour.Value); - formation.Organisme = formationDTO.Organisme; - formation.EstCertifiee = formationDTO.EstCertifiee.Value; - //formation.EstRealisee = formationDTO.EstRealisee.Value; - formation.Origine = GetOrigineFormation(formationDTO.Origine); - formation.Statut = GetStatutFormation(formationDTO.Statut); - formation.ModeFormation = GetModeFormation(formationDTO.Mode); - formation.TypeFormation = GetTypeFormation(formationDTO.Type); - - return formation; - } - - /// - /// Récuperer un objet OrigineFormation en fonction d'un objet OrigineFormationDTO - /// - /// - /// - private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO) - { - if (origineFormationDTO == null) - return null; - - OrigineFormation origineFormation = new OrigineFormation() - { - IdOrigineFormation = origineFormationDTO.Id.Value, - Libelle = origineFormationDTO.Libelle - }; - - return origineFormation; - } - - /// - /// Récuperer un objet StatutFormation en fonction d'un objet StatutFormationDTO - /// - /// - /// - private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO) - { - if (statutFormationDTO == null) - return null; - - StatutFormation statutFormation = new StatutFormation() - { - IdStatutFormation = statutFormationDTO.Id.Value, - Libelle = statutFormationDTO.Libelle - }; - - return statutFormation; - } - - /// - /// Récuperer un objet ModeFormation en fonction d'un objet ModeFormationDTO - /// - /// - /// - private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO) - { - if (modeFormationDTO == null) - return null; - - ModeFormation modeFormation = new ModeFormation() - { - IdModeFormation = modeFormationDTO.Id.Value, - Libelle = modeFormationDTO.Libelle - }; - - return modeFormation; - } - - /// - /// Récuperer un objet TypeFormation en fonction d'un objet TypeFormationDTO - /// - /// - /// - private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO) - { - if (typeFormationDTO == null) - return null; - - TypeFormation typeFormation = new TypeFormation() - { - IdTypeFormation = typeFormationDTO.Id.Value, - Libelle = typeFormationDTO.Libelle - }; - - return typeFormation; - } - - #endregion - #endregion } diff --git a/EPAServeur/Services/NoteService.cs b/EPAServeur/Services/NoteService.cs index 00f0dcf..736b939 100644 --- a/EPAServeur/Services/NoteService.cs +++ b/EPAServeur/Services/NoteService.cs @@ -32,13 +32,19 @@ namespace EPAServeur.Services /// Service collaborateur pour récupérer les données collaborateurs au format DTO /// private readonly ICollaborateurService collaborateurService; + + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; #endregion #region Constructeurs - public NoteService(ICollaborateurApi _collaborateurApi, ICollaborateurService _collaborateurService, EpContext _context) + public NoteService(ICollaborateurApi _collaborateurApi, ICollaborateurService _collaborateurService, EpContext _context, ITransformDTO _transformDTO) { collaborateurService = _collaborateurService; collaborateurApi = _collaborateurApi; context = _context; + transformDTO = _transformDTO; } #endregion @@ -66,7 +72,7 @@ namespace EPAServeur.Services //transformer la note DTO en Note - Note note = DetailsNoteDTOToNouvelleNote(nouvelleNote); + Note note = transformDTO.DetailsNoteDTOToNouvelleNote(nouvelleNote); //ajouter la note et sauvegarder await context.Note.AddAsync(note); @@ -111,7 +117,7 @@ namespace EPAServeur.Services if (auteur == null) throw new ReferentNotFoundException("L'auteur de la note n'existe pas"); - return NoteToDetailSDTO(note, await collaborateurService.GetCollaborateurByIdAsync(note.IdCollaborateur)); + return transformDTO.NoteToDetailSDTO(note, await collaborateurService.GetCollaborateurByIdAsync(note.IdCollaborateur)); } /// @@ -134,7 +140,7 @@ namespace EPAServeur.Services List guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList(); IEnumerable collaborateurs = await collaborateurApi.ChercherCollabAsync(guids); - IEnumerable AffichageNoteDTO = notes.Select(note => NoteToAffichageDTO(note, collaborateurs)); + IEnumerable AffichageNoteDTO = notes.Select(note => transformDTO.NoteToAffichageDTO(note, collaborateurs)); int skip = (numPage.Value - 1) * parPage.Value; @@ -173,7 +179,7 @@ namespace EPAServeur.Services List guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList(); IEnumerable collaborateurs = await collaborateurApi.ChercherCollabAsync(guids); - IEnumerable AffichageNoteDTO = notes.Select(note => NoteToAffichageDTO(note, collaborateurs)); + IEnumerable AffichageNoteDTO = notes.Select(note => transformDTO.NoteToAffichageDTO(note, collaborateurs)); if (texte != null) { @@ -274,77 +280,5 @@ namespace EPAServeur.Services } #endregion - #region ObjectToDTO - - - /// - /// Transformer un objet note en objet pour afficher un note dans dans un tableau - /// - /// Note à transformer - /// Service collaborateur pour récupérer les informations des collaborateurs - /// La note transformée pour être affichée - private AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable collaborateurs) - { - Collaborateur collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(note.IdCollaborateur)); - string infoCollab = "Aucun collaborateur lié"; - if (collaborateur != null) - infoCollab = collaborateur.Nom + " " + collaborateur.Prenom; - AffichageNoteDTO affichage = new AffichageNoteDTO() - { - Id = note.IdNote, - IdCollaborateur = note.IdCollaborateur, - Collaborateur = infoCollab, - Titre = note.Titre, - DateMiseAJour = note.DateMiseAJour - }; - return affichage; - } - - - - /// - /// Transformatino d'une note en DetailsNoteDTO de manière asynchrone - /// - /// Note à transformer - /// Note transformer en DetailsNoteDTO - private DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur) - { - if (collaborateur == null) - throw new CollaborateurNotFoundException("Il est impossible de récupérer une note donc le collaborateur n'existe plus"); - DetailsNoteDTO details = new DetailsNoteDTO() - { - Id = note.IdNote, - DateCreation = note.DateCreation, - DateMiseAjour = note.DateMiseAJour, - Titre = note.Titre, - Texte = note.Texte, - IdAuteur = note.IdAuteur, - Collaborateur = collaborateur, - }; - return details; - } - #endregion - - #region DTOToObject - /// - /// Transformer l'objet DTO d'une note en note - /// - /// En général, de base, cette méthode est prévue pour être utilisée qu'à la création d'une nouvelle note, dateCreation et dateUpdate sont donc initialisée à ce moment là - /// Objet DTO à transformer en note - /// L'objet DTO transformé en note - private Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO) - { - Note note = new Note() - { - IdAuteur = detailsNoteDTO.IdAuteur.Value, - IdCollaborateur = detailsNoteDTO.Collaborateur.Id.Value, - Texte = detailsNoteDTO.Texte, - Titre = detailsNoteDTO.Titre, - DateCreation = detailsNoteDTO.DateCreation.Value, - DateMiseAJour = detailsNoteDTO.DateMiseAjour.Value - }; - return note; - } - #endregion } } diff --git a/EPAServeur/Services/ParticipationFormationService.cs b/EPAServeur/Services/ParticipationFormationService.cs index 37ff1f3..57459ec 100644 --- a/EPAServeur/Services/ParticipationFormationService.cs +++ b/EPAServeur/Services/ParticipationFormationService.cs @@ -28,6 +28,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + #endregion #region Contructeurs @@ -36,10 +41,11 @@ namespace EPAServeur.Services /// Constructeur de la classe FormationService /// /// - public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService) + public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO) { epContext = _epContext; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -63,7 +69,7 @@ namespace EPAServeur.Services if (participationFormation == null) throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation)); - return GetEvaluationDTO(participationFormation); + return transformDTO.GetEvaluationDTO(participationFormation); } /// @@ -87,9 +93,9 @@ namespace EPAServeur.Services participationFormations = await query.ToListAsync(); - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(participationFormations); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(participationFormations); - participationFormationDTOs = participationFormations.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs)); + participationFormationDTOs = participationFormations.Select(participationFormation => transformDTO.GetParticipationFormationDTO(participationFormation, collaborateurDTOs)); return participationFormationDTOs; } @@ -116,12 +122,12 @@ namespace EPAServeur.Services if (participationFormation == null) throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation)); - participationFormation.Evaluation = evaluationDTO.Saisies.Select(s => GetSaisie(s)).ToList(); + participationFormation.Evaluation = evaluationDTO.Saisies.Select(s => transformDTO.GetSaisie(s)).ToList(); participationFormation.EstEvaluee = true; await epContext.SaveChangesAsync(); - return GetEvaluationDTO(participationFormation); + return transformDTO.GetEvaluationDTO(participationFormation); } #endregion @@ -163,238 +169,6 @@ namespace EPAServeur.Services throw new ParticipationFormationInvalidException("Toutes les saisies de type compétence ou notation doivent posséder une note."); } - #region Object to DTO - - /// - /// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null) - return null; - - if (collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO() - { - Id = participationFormation.IdParticipationFormation, - DateCreation = participationFormation.DateCreation, - Intitule = participationFormation.Formation.Intitule, - DateDebut = participationFormation.Formation.DateDebut, - EstEvaluee = participationFormation.EstEvaluee, - Statut = GetStatutFormationDTO(participationFormation.Formation.Statut), - Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs), - Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs) - }; - - return participationFormationDTO; - } - - - /// - /// Récuperer un objet EvaluationDTO en fonction d'un objet ParticipationFormation - /// - /// - /// - private EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation) - { - if (participationFormation == null) - return null; - - EvaluationDTO evaluationDTO = new EvaluationDTO() - { - Id = participationFormation.IdParticipationFormation, - Intitule = participationFormation.Formation.Intitule, - DateDebut = participationFormation.Formation.DateDebut, - EstCertifiee = participationFormation.Formation.EstCertifiee, - Saisies = participationFormation.Evaluation.Select(s => GetSaisieDTO(s)).ToList() - }; - - return evaluationDTO; - } - - /// - /// Récuperer un objet SaisieDTO en fonction d'un objet Saisie - /// - /// - /// - private SaisieDTO GetSaisieDTO(Saisie saisie) - { - if (saisie == null) - return null; - - SaisieDTO saisieDTO = new SaisieDTO() - { - Id = saisie.IdSaisie, - Note = saisie.Note, - Texte = saisie.Texte, - Champ = GetChampDTO(saisie.Champ), - TypeSaisie = saisie.TypeSaisie - }; - return saisieDTO; - } - - /// - /// Récuperer un objet ChampDTO en fonction d'un objet Champ - /// - /// - /// - private ChampDTO GetChampDTO(Champ champ) - { - if (champ == null) - return null; - - ChampDTO champDTO = new ChampDTO() - { - Id = champ.IdChamp, - Texte = champ.Texte, - Section = champ.Section, - Soussection = champ.SousSection, - Ordre = champ.Ordre, - TypeChamp = champ.TypeChamp, - TypeSaisie = champ.TypeSaisie - }; - return champDTO; - } - - /// - /// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation - /// - /// - /// - private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation) - { - if (statutFormation == null) - return null; - - StatutFormationDTO statutFormationDTO = new StatutFormationDTO() - { - Id = statutFormation.IdStatutFormation, - Libelle = statutFormation.Libelle - }; - return statutFormationDTO; - } - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation. - /// - /// - /// - private async Task> GetCollaborateurDTOs(IEnumerable participationsFormation) - { - if (participationsFormation == null || !participationsFormation.Any()) - return null; - - List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; - } - - /// - /// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null) - return null; - - if (collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur); - } - - /// - /// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO - /// - /// - /// - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurDTOs) - { - CollaborateurDTO collaborateur; - CollaborateurDTO referent; - - if (ep == null) - return null; - - if (collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - - collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur); - referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent); - - EpInformationDTO epInformationDTO = new EpInformationDTO() - { - Id = ep.IdEP, - Type = ep.TypeEP, - Statut = ep.Statut, - DateDisponibilite = ep.DateDisponibilite, - DatePrevisionnelle = ep.DatePrevisionnelle, - Obligatoire = ep.Obligatoire, - Collaborateur = collaborateur, - Referent = referent, - }; - - return epInformationDTO; - } - - #endregion - - #region DTO to Object - - /// - /// Récuperer un objet Saisie en fonction d'un objet SaisieDTO - /// - /// - /// - private Saisie GetSaisie(SaisieDTO saisieDTO) - { - if (saisieDTO == null) - return null; - - Saisie saisie = new Saisie() - { - //IdSaisie = saisieDTO.Id.Value, - Note = saisieDTO.Note, - Texte = saisieDTO.Texte, - Champ = GetChamp(saisieDTO.Champ), - TypeSaisie = saisieDTO.TypeSaisie - }; - - return saisie; - } - - /// - /// Récuperer un objet Champ en fonction d'un objet ChampDTO - /// - /// - /// - private Champ GetChamp(ChampDTO champDTO) - { - if (champDTO == null) - return null; - - Champ champ = new Champ() - { - IdChamp = champDTO.Id.Value, - Texte = champDTO.Texte, - Section = champDTO.Section, - SousSection = champDTO.Soussection, - Ordre = champDTO.Ordre.Value, - TypeChamp = champDTO.TypeChamp, - TypeSaisie = champDTO.TypeSaisie - }; - return champ; - } - - #endregion - #endregion }