using EPAServeur.Context; using EPAServeur.Exceptions; using EPAServeur.IServices; using EPAServeur.Models.Formation; using IO.Swagger.DTO; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace EPAServeur.Services { public class FormationService : IFormationService { #region Variables private readonly EpContext epContext; #endregion #region Contructeurs /// /// Constructeur de la classe FormationService /// /// public FormationService(EpContext _epContext) { epContext = _epContext; } #endregion #region Méthodes Service /// /// Récupérer une formation par son id /// /// /// public FormationDTO GetFormationById(long? idFormation) { Formation formation = epContext.Formation.Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) .FirstOrDefault(formation => formation.IdFormation == idFormation); if (formation == null) throw new FormationNotFoundException(); return GetFormationDTO(formation); } /// /// Récupérer une formation par son id de manière asynchrone /// /// /// public async Task GetFormationByIdAsync(long? idFormation) { Formation formation = await epContext.Formation.Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) .FirstOrDefaultAsync(formation => formation.IdFormation == idFormation); if (formation == null) throw new FormationNotFoundException(); return GetFormationDTO(formation); } /// /// Récupérer la liste des formations /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public IEnumerable GetFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (statutFormation != null && idAgence != null) { formations = epContext.Formation .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) .Where(formation => formation.Statut.IdStatutFormation == statutFormation && formation.IdAgence == idAgence).Skip(skip).Take(take); } else if (statutFormation != null && idAgence == null) { formations = epContext.Formation .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) .Where(formation => formation.Statut.IdStatutFormation == statutFormation).Skip(skip).Take(take); } else if (idAgence != null) { formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); } else { formations = epContext.Formation.Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); } formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer la liste des formations de manière asynchrone /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public async Task> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (statutFormation != null && idAgence != null) { formations = await epContext.Formation .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) .Where(formation => formation.Statut.IdStatutFormation == statutFormation && formation.IdAgence == idAgence).Skip(skip).Take(take).ToListAsync(); } else if (statutFormation != null && idAgence == null) { formations = await epContext.Formation .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation) .Where(formation => formation.Statut.IdStatutFormation == statutFormation).Skip(skip).Take(take).ToListAsync(); } else if (idAgence != null) { formations = await epContext.Formation .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Where(formation => formation.IdAgence == idAgence).Skip(skip).Take(take).ToListAsync(); } else { formations = await epContext.Formation.Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); } formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les formations annulées /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public IEnumerable GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (idAgence != null) formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.IdStatutFormation == 4) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); else formations = epContext.Formation.Where(formation => formation.Statut.IdStatutFormation == 4) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les formations annulées de manière asynchrone /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public async Task> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (idAgence != null) formations = await epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.IdStatutFormation == 4) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); else formations = await epContext.Formation.Where(formation => formation.Statut.IdStatutFormation == 4) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les formations réalisées /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public IEnumerable GetFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (idAgence != null) { formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.IdStatutFormation == 3) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); } else { formations = epContext.Formation.Where(formation => formation.Statut.IdStatutFormation == 3) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); } formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les formations réalisées de manière asynchrone /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public async Task> GetFormationRealiseesAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (idAgence != null) { formations = await epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.IdStatutFormation == 3) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); } else { formations = await epContext.Formation.Where(formation => formation.Statut.IdStatutFormation == 3) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); } formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les formations plannifiées et replannifiées /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public IEnumerable GetProchainesFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (idAgence != null) { formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && (formation.Statut.IdStatutFormation == 1 || formation.Statut.IdStatutFormation == 2)) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); } else { formations = epContext.Formation.Where(formation => (formation.Statut.IdStatutFormation == 1 || formation.Statut.IdStatutFormation == 2)) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take); } formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les formations plannifiées et replannifiées de manère asynchrone /// /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) /// Numéro de la page du tableau qui affiche les données /// Nombre d'éléments affiché sur chaque page du tableau /// id de l'agence à laquelle sont rattachées les données à récupérer /// Texte permettant d'identifier l'objet rechercher /// Colonne du tableau sur lequel le tri s'effectue /// public async Task> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { IEnumerable formations; IEnumerable formationDTOs; if (texte == null) texte = ""; else texte = texte.ToLower(); int skip = (numPage.Value - 1) * parPAge.Value; int take = parPAge.Value; if (idAgence != null) { formations = await epContext.Formation.Where(formation => formation.IdAgence == idAgence && (formation.Statut.IdStatutFormation == 1 || formation.Statut.IdStatutFormation == 2)) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); } else { formations = await epContext.Formation.Where(formation => (formation.Statut.IdStatutFormation == 1 || formation.Statut.IdStatutFormation == 2)) .Include(formation => formation.Statut) .Include(formation => formation.ModeFormation) .Include(formation => formation.Origine) .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); } formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); return formationDTOs; } /// /// Récupérer les modes de formation /// /// public IEnumerable GetModesFormation() { IEnumerable modeFormations; IEnumerable modeFormationDTOs; modeFormations = epContext.ModeFormation; modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); return modeFormationDTOs; } /// /// Récupérer les modes de formation de manière asynchrone /// /// public async Task> GetModesFormationAsync() { IEnumerable modeFormations; IEnumerable modeFormationDTOs; modeFormations = await epContext.ModeFormation.ToListAsync(); modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); return modeFormationDTOs; } /// /// Récupérer les origines de formation /// /// public IEnumerable GetOriginesFormation() { IEnumerable origineFormations; IEnumerable origineFormationDTOs; origineFormations = epContext.OrigineFormation; origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); return origineFormationDTOs; } /// /// Récupérer les origines de formation de manière asynchrone /// /// public async Task> GetOriginesFormationAsync() { IEnumerable origineFormations; IEnumerable origineFormationDTOs; origineFormations = await epContext.OrigineFormation.ToListAsync(); origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); return origineFormationDTOs; } /// /// Récupérer les statuts de formation /// /// public IEnumerable GetStatutsFormation() { IEnumerable statutFormations; IEnumerable statutFormationDTOs; statutFormations = epContext.StatutFormation; statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); return statutFormationDTOs; } /// /// Récupérer les statuts de formation de manière asynchrone /// /// public async Task> GetStatutsFormationAsync() { IEnumerable statutFormations; IEnumerable statutFormationDTOs; statutFormations = await epContext.StatutFormation.ToListAsync(); statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); return statutFormationDTOs; } /// /// Récupérer les types de formation /// /// public IEnumerable GetTypesFormation() { IEnumerable typeFormations; IEnumerable typeFormationDTOs; typeFormations = epContext.TypeFormation; typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); return typeFormationDTOs; } /// /// Récupérer les types de formation de manière asynchrone /// /// public async Task> GetTypesFormationAsync() { IEnumerable typeFormations; IEnumerable typeFormationDTOs; typeFormations = await epContext.TypeFormation.ToListAsync(); typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); return typeFormationDTOs; } /// /// Ajouter une formation /// /// /// public FormationDTO AddFormation(FormationDTO formationDTO) { if (!IsFormationValide(formationDTO)) throw new FormationInvalidException(); Formation formation = new Formation(); formation = SetFormation(formation, formationDTO); epContext.StatutFormation.Attach(formation.Statut); epContext.OrigineFormation.Attach(formation.Origine); epContext.ModeFormation.Attach(formation.ModeFormation); epContext.TypeFormation.Attach(formation.TypeFormation); epContext.Add(formation); epContext.SaveChanges(); return GetFormationDTO(formation); } /// /// Ajouter une formation de manière asynchrone /// /// /// public async Task AddFormationAsync(FormationDTO formationDTO) { if (!await IsFormationValideAsync(formationDTO)) throw new FormationInvalidException(); Formation formation = new Formation(); formation = SetFormation(formation, formationDTO); epContext.StatutFormation.Attach(formation.Statut); epContext.OrigineFormation.Attach(formation.Origine); epContext.ModeFormation.Attach(formation.ModeFormation); epContext.TypeFormation.Attach(formation.TypeFormation); epContext.Add(formation); await epContext.SaveChangesAsync(); return GetFormationDTO(formation); } /// /// Modifier une formation /// /// /// /// public FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO) { if (!IsFormationValide(formationDTO)) throw new FormationInvalidException(); if (!formationDTO.Id.HasValue || formationDTO.Id.Value != idFormation) throw new FormationIncompatibleIdException(); Formation formation = epContext.Formation.Find(idFormation.Value); if (formation == null) return null; formation = SetFormation(formation, formationDTO); epContext.SaveChanges(); return GetFormationDTO(formation); } /// /// Modifier une formation de manière asynchrone /// /// /// /// public async Task UpdateFormationAsync(long? idFormation, FormationDTO formationDTO) { if (!IsFormationValide(formationDTO)) throw new FormationInvalidException(); if (!formationDTO.Id.HasValue || formationDTO.Id.Value != idFormation) throw new FormationIncompatibleIdException(); Formation formation = await epContext.Formation.FindAsync(idFormation.Value); if (formation == null) return null; formation = SetFormation(formation, formationDTO); await epContext.SaveChangesAsync(); return GetFormationDTO(formation); } /// /// Supprimer une formation /// /// /// public FormationDTO DeleteFormationById(long? idFormation) { if (!idFormation.HasValue) throw new FormationIncompatibleIdException(); Formation formation = epContext.Formation.Find(idFormation.Value); if (formation == null) throw new FormationNotFoundException(); epContext.Remove(formation); epContext.SaveChanges(); return GetFormationDTO(formation); } /// /// Supprimer une formation de manière asynchrone /// /// /// public async Task DeleteFormationByIdAsync(long? idFormation) { if (!idFormation.HasValue) throw new FormationIncompatibleIdException(); Formation formation = await epContext.Formation.FindAsync(idFormation.Value); if (formation == null) throw new FormationNotFoundException(); epContext.Remove(formation); await epContext.SaveChangesAsync(); return GetFormationDTO(formation); } #endregion #region Méthodes Privée /// /// Vérifier si un objet FormationDTO est valide pour ajout ou mise à jour /// /// Un objet FormationDTO est valide si aucune de ses propriétés n'est à null,si la date de début de la formation est inférieur à la date de fin et si le statut, l'origine,le mode et le type sont présents dans la base de données /// /// true si l'objet est valide, false sinon private bool IsFormationValide(FormationDTO formation) { return !(formation == null || formation.Statut == null || formation.Mode == null || formation.Origine == null || formation.Type == null || !formation.IdAgence.HasValue || formation.IdAgence == 0 || string.IsNullOrWhiteSpace(formation.Intitule) || string.IsNullOrWhiteSpace(formation.Organisme) || !formation.DateDebut.HasValue || !formation.DateFin.HasValue || formation.DateDebut.Value > formation.DateFin.Value || !formation.Statut.Id.HasValue || !formation.Mode.Id.HasValue || !formation.Origine.Id.HasValue || !formation.Type.Id.HasValue || !epContext.StatutFormation.Any(statut => statut.IdStatutFormation == formation.Statut.Id.Value && statut.Libelle == formation.Statut.Libelle) || !epContext.ModeFormation.Any(mode => mode.IdModeFormation == formation.Mode.Id.Value && mode.Libelle == formation.Mode.Libelle) || !epContext.OrigineFormation.Any(origine => origine.IdOrigineFormation == formation.Origine.Id.Value && origine.Libelle == formation.Origine.Libelle) || !epContext.TypeFormation.Any(type => type.IdTypeFormation == formation.Type.Id.Value && type.Libelle == formation.Type.Libelle)); } /// /// Vérifier si un objet FormationDTO est valide pour ajout ou mise à jour /// /// Un objet FormationDTO est valide si aucune de ses propriétés n'est à null,si la date de début de la formation est inférieur à la date de fin et si le statut, l'origine,le mode et le type sont présents dans la base de données /// /// true si l'objet est valide, false sinon private async Task IsFormationValideAsync(FormationDTO formation) { return !(formation == null || formation.Statut == null || formation.Mode == null || formation.Origine == null || formation.Type == null || !formation.IdAgence.HasValue || formation.IdAgence == 0 || string.IsNullOrWhiteSpace(formation.Intitule) || string.IsNullOrWhiteSpace(formation.Organisme) || !formation.DateDebut.HasValue || !formation.DateFin.HasValue || formation.DateDebut.Value > formation.DateFin.Value || !formation.Statut.Id.HasValue || !formation.Mode.Id.HasValue || !formation.Origine.Id.HasValue || !formation.Type.Id.HasValue || ! await epContext.StatutFormation.AnyAsync(statut => statut.IdStatutFormation == formation.Statut.Id.Value && statut.Libelle == formation.Statut.Libelle) || ! await epContext.ModeFormation.AnyAsync(mode => mode.IdModeFormation == formation.Mode.Id.Value && mode.Libelle == formation.Mode.Libelle) || ! await epContext.OrigineFormation.AnyAsync(origine => origine.IdOrigineFormation == formation.Origine.Id.Value && origine.Libelle == formation.Origine.Libelle) || ! await epContext.TypeFormation.AnyAsync(type => type.IdTypeFormation == formation.Type.Id.Value && type.Libelle == formation.Type.Libelle)); } #region Object to DTO /// /// Récupère un objet FormationDTO en fonction d'un objet Formation /// /// /// private FormationDTO GetFormationDTO(Formation formation) { 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, Origine = GetOrigineFormationDTO(formation.Origine), Statut = GetStatutFormationDTO(formation.Statut), Mode = GetModeFormationDTO(formation.ModeFormation), Type = GetTypeFormationDTO(formation.TypeFormation) }; return formationDTO; } /// /// Récupère 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écupère 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écupère 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écupère 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; } #endregion #region DTO to Object /// /// Modifie un objet Formation en fonction d'un objet FormationDTO /// /// /// /// private Formation SetFormation(Formation formation, FormationDTO formationDTO) { 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.Origine = GetOrigineFormation(formationDTO.Origine); formation.Statut = GetStatutFormation(formationDTO.Statut); formation.ModeFormation = GetModeFormation(formationDTO.Mode); formation.TypeFormation = GetTypeFormation(formationDTO.Type); return formation; } /// /// Récupère un objet OrigineFormation en fonction d'un objet OrigineFormationDTO /// /// /// private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO) { OrigineFormation origineFormation = new OrigineFormation() { IdOrigineFormation = origineFormationDTO.Id.Value, Libelle = origineFormationDTO.Libelle }; return origineFormation; } /// /// Récupère un objet StatutFormation en fonction d'un objet StatutFormationDTO /// /// /// private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO) { StatutFormation statutFormation = new StatutFormation() { IdStatutFormation = statutFormationDTO.Id.Value, Libelle = statutFormationDTO.Libelle }; return statutFormation; } /// /// Récupère un objet ModeFormation en fonction d'un objet ModeFormationDTO /// /// /// private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO) { ModeFormation modeFormation = new ModeFormation() { IdModeFormation = modeFormationDTO.Id.Value, Libelle = modeFormationDTO.Libelle }; return modeFormation; } /// /// Récupère un objet TypeFormation en fonction d'un objet TypeFormationDTO /// /// /// private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO) { TypeFormation typeFormation = new TypeFormation() { IdTypeFormation = typeFormationDTO.Id.Value, Libelle = typeFormationDTO.Libelle }; return typeFormation; } #endregion #endregion } }