You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Digitalisation_EPA_Serveur/EPAServeur/Services/TransformDTO.cs

865 lines
34 KiB

using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.IServices;
using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using EPAServeur.Models.Notes;
using EPAServeur.Models.SaisieChamp;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
using IO.Swagger.ModelCollaborateur;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Services
{
public class TransformDTO : ITransformDTO
{
/// <summary>
/// Transformer un objet DetailsNoteDTO en objet Note.
/// </summary>
/// <remarks>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à</remarks>
/// <param name="detailsNoteDTO">Objet DTO à transformer en note</param>
/// <returns>L'objet DTO transformé en note</returns>
public 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;
}
/// <summary>
/// Transformer un objet Ep en objet EpInformationDTO.
/// La liste des collaborateurs est utilisé pour alimenter le collaborateur et le référent de l'objet EpInformationDTO.
/// </summary>
/// <param name="ep"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public EpInformationDTO EpToEpDTO(Ep ep, IEnumerable<CollaborateurDTO> 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
};
}
/// <summary>
/// Transformer un objet Agence en objet AgenceDTO.
/// </summary>
/// <param name="agence"></param>
/// <returns></returns>
public AgenceDTO GetAgenceDTO(Agence agence)
{
if (agence == null)
return null;
AgenceDTO agenceDTO = new AgenceDTO()
{
Id = agence.Id,
Nom = agence.Nom,
Bu = new List<BusinessUnitDTO>()
};
agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO()
{
Id = bu.Id,
Nom = bu.Nom
}).ToList();
return agenceDTO;
}
/// <summary>
/// Transformer une objet BU en objet BusinessUnitDTO.
/// </summary>
/// <param name="businessUnit"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Récupérer un objet Champ en objet ChampDTO.
/// </summary>
/// <param name="champDTO"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Transformer un objet Champ en objet ChampDTO.
/// </summary>
/// <param name="champ"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Récupérer le collaborateur qui participe à la formation.
/// </summary>
/// <param name="participationFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur);
}
/// <summary>
/// Récupérer le collaborateur qui a fait une demande de formation.
/// </summary>
/// <param name="demandeFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public CollaborateurDTO GetCollaborateurDTO(DemandeFormation demandeFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (demandeFormation == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == demandeFormation.Ep.IdCollaborateur);
}
/// <summary>
/// Transformer un objet DemandeDelegation en objet DemandeDelegationDTO.
/// L'objet CollaborateurDTO est utilisé pour alimenter la propriété Referent de l'objet DemandeDelegationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Ep de l'objet DemandeDelegationDTO.
/// </summary>
/// <param name="demande"></param>
/// <param name="referent"></param>
/// <param name="collaborateurs"></param>
/// <returns></returns>
public DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable<CollaborateurDTO> collaborateurs)
{
return new DemandeDelegationDTO()
{
Id = demande.IdDemandeDelegation,
DateDemande = demande.DateDemande,
EtatDemande = demande.EtatDemande,
Referent = referent,
RaisonDemande = demande.RaisonDemande,
Ep = GetEpInformationDTO(demande.Ep, collaborateurs)
};
}
/// <summary>
/// Transformer un objet Engagement en objet EngagementDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Ep de l'objet EngagementDTO.
/// </summary>
/// <param name="engagement"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable<CollaborateurDTO> 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;
}
/// <summary>
/// Transformer un objet Ep en objet EpInformationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Referent de l'objet EpInformationDTO.
/// </summary>
/// <param name="ep"></param>
/// <param name="collaborateurs"></param>
/// <returns></returns>
public EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurs)
{
CollaborateurDTO collaborateur;
CollaborateurDTO referent;
if (ep == null || collaborateurs == null || !collaborateurs.Any())
return null;
collaborateur = collaborateurs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur);
referent = collaborateurs.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;
}
/// <summary>
/// Transformer un objet ParticipationFormation en objet EvaluationDTO.
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Transformer un objet Formation en objet FormationDetailsDTO.
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Transformer un objet Formation en objet FormationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Participations de l'objet FormationDTO.
/// </summary>
/// <param name="formation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public FormationDTO GetFormationDTO(Formation formation, IEnumerable<CollaborateurDTO> 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;
}
/// <summary>
/// Transformer un objet Formation en objet FormationDTO et laisser la propriété Participations de l'objet FormationDTO null.
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
public FormationDTO GetFormationDTOWhitoutParticipationFormation(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;
}
/// <summary>
/// Transformer un objet ModeFormationDTO en objet ModeFormation.
/// </summary>
/// <param name="modeFormationDTO"></param>
/// <returns></returns>
public ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO)
{
if (modeFormationDTO == null)
return null;
ModeFormation modeFormation = new ModeFormation()
{
IdModeFormation = modeFormationDTO.Id.Value,
Libelle = modeFormationDTO.Libelle
};
return modeFormation;
}
/// <summary>
/// Transformer un objet ModeFormation en objet ModeFormationDTO.
/// </summary>
/// <param name="modeFormation"></param>
/// <returns></returns>
public ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation)
{
if (modeFormation == null)
return null;
ModeFormationDTO modeFormationDTO = new ModeFormationDTO()
{
Id = modeFormation.IdModeFormation,
Libelle = modeFormation.Libelle
};
return modeFormationDTO;
}
/// <summary>
/// Transformer un objet OrigineFormationDTO en objet OrigineFormation.
/// </summary>
/// <param name="origineFormationDTO"></param>
/// <returns></returns>
public OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO)
{
if (origineFormationDTO == null)
return null;
OrigineFormation origineFormation = new OrigineFormation()
{
IdOrigineFormation = origineFormationDTO.Id.Value,
Libelle = origineFormationDTO.Libelle
};
return origineFormation;
}
/// <summary>
/// Transformer un objet OrigineFormation en objet OrigineFormationDTO.
/// </summary>
/// <param name="origineFormation"></param>
/// <returns></returns>
public OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation)
{
if (origineFormation == null)
return null;
OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO()
{
Id = origineFormation.IdOrigineFormation,
Libelle = origineFormation.Libelle
};
return origineFormationDTO;
}
/// <summary>
/// Transformer un objet ParticipationFormation en objet ParticipationFormationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO.
/// </summary>
/// <param name="participationFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> 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;
}
/// <summary>
/// Transformer une liste d'objets ParticipationFormation en liste d'objets ParticipationFormationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO.
/// </summary>
/// <param name="participationsFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public List<ParticipationFormationDTO> GetParticipationsFormationDTO(List<ParticipationFormation> participationsFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
List<ParticipationFormationDTO> 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;
}
// <summary>
/// Récuperer un objet OrigineDemandeFormationDTO en fonction d'un objet OrigineDemande
/// </summary>
/// <param name="origineDemande"></param>
/// <returns></returns>
public OrigineDemandeFormationDTO GetOrigineDemandeFormationDTO(OrigineDemande origineDemande)
{
if (origineDemande == null)
return null;
OrigineDemandeFormationDTO origineDemandeFormationDTO = new OrigineDemandeFormationDTO()
{
Id = origineDemande.IdOrigineDemande,
Libelle = origineDemande.Libelle
};
return origineDemandeFormationDTO;
}
/// <summary>
/// Récuperer un objet DemandeFormationDTO en fonction d'un objet DemandeFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="demandeFormation"></param>
/// <returns></returns>
public DemandeFormationDTO GetDemandeFormationDTO(DemandeFormation demandeFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (demandeFormation == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
Formation formation;
if (demandeFormation.ParticipationFormation != null)
formation = demandeFormation.ParticipationFormation.Formation;
else
formation = null;
DemandeFormationDTO demandeFormationDTO = new DemandeFormationDTO()
{
Id = demandeFormation.IdDemandeFormation,
Libelle = demandeFormation.Libelle,
Description = demandeFormation.Description,
DemandeRH = demandeFormation.DemandeRH,
DateDemande = demandeFormation.DateDemande,
EtatDemande = demandeFormation.Etat,
CommentaireRefus = demandeFormation.CommentaireRefus,
DateDerniereReponse = demandeFormation.DateDerniereReponse,
Origine = GetOrigineDemandeFormationDTO(demandeFormation.OrigineDemande),
Collaborateur = GetCollaborateurDTO(demandeFormation, collaborateurDTOs),
Ep = GetEpInformationDTO(demandeFormation.Ep, collaborateurDTOs),
Formation = GetFormationDetailsDTO(formation)
};
return demandeFormationDTO;
}
/// <summary>
/// Transformer un objet SaisieDTO en objet Saisie.
/// </summary>
/// <param name="saisieDTO"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Transformer un objet Saisie en objet SaisieDTO.
/// </summary>
/// <param name="saisie"></param>
/// <returns></returns>
public 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;
}
/// <summary>
/// Transformer un objet StatutFormationDTO en objet StatutFormation.
/// </summary>
/// <param name="statutFormationDTO"></param>
/// <returns></returns>
public StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO)
{
if (statutFormationDTO == null)
return null;
StatutFormation statutFormation = new StatutFormation()
{
IdStatutFormation = statutFormationDTO.Id.Value,
Libelle = statutFormationDTO.Libelle
};
return statutFormation;
}
/// <summary>
/// Transformer un objet StatutFormation en objet StatutFormationDTO.
/// </summary>
/// <param name="statutFormation"></param>
/// <returns></returns>
public StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
{
if (statutFormation == null)
return null;
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
{
Id = statutFormation.IdStatutFormation,
Libelle = statutFormation.Libelle
};
return statutFormationDTO;
}
/// <summary>
/// Transformer un objet TypeFormationDTO en objet TypeFormation.
/// </summary>
/// <param name="typeFormationDTO"></param>
/// <returns></returns>
public TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO)
{
if (typeFormationDTO == null)
return null;
TypeFormation typeFormation = new TypeFormation()
{
IdTypeFormation = typeFormationDTO.Id.Value,
Libelle = typeFormationDTO.Libelle
};
return typeFormation;
}
/// <summary>
/// Transformer un objet TypeFormation en objet TypeFormationDTO.
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
public TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation)
{
if (typeFormation == null)
return null;
TypeFormationDTO typeFormationDTO = new TypeFormationDTO()
{
Id = typeFormation.IdTypeFormation,
Libelle = typeFormation.Libelle
};
return typeFormationDTO;
}
/// <summary>
/// Transformer un objet Note en objet AffichageNoteDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur (nom et prénom) de l'objet AffichageNoteDTO.
/// </summary>
/// <param name="note"></param>
/// <param name="collaborateurs"></param>
/// <returns></returns>
public AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable<Collaborateur> 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;
}
/// <summary>
/// Transformer un objet Note en objet DetailsNoteDTO.
/// L'objet CollaborateurDTO est utilisé pour alimenter la propriété Collaborateur de l'objet DetailsNoteDTO.
/// </summary>
/// <param name="note"></param>
/// <param name="collaborateur"></param>
/// <returns></returns>
public 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;
}
// <summary>
/// Récupérer un objet OrigineDemande en fonction d'un objet OrigineDemandeFormationDTO
/// </summary>
/// <param name="origineDemande"></param>
/// <returns></returns>
public OrigineDemande GetOrigineDemandeFormation(OrigineDemandeFormationDTO origineDemandeDTO)
{
if (origineDemandeDTO == null)
return null;
OrigineDemande origineDemandeFormation = new OrigineDemande()
{
IdOrigineDemande = origineDemandeDTO.Id.Value,
Libelle = origineDemandeDTO.Libelle
};
return origineDemandeFormation;
}
/// <summary>
/// Mettre à jour un objet DemandeFormation en fonction d'un objet DemandeFormationDTO.
/// </summary>
/// <remarks>Les propriétés ParticipationFormation et Ep ne sont pas mise à jour.</remarks>
/// <param name="formation"></param>
/// <param name="formationDTO"></param>
/// <returns></returns>
public DemandeFormation SetDemandeFormationWithoutParticipationFormationAndEp(DemandeFormation demandeFormation, DemandeFormationDTO demandeFormationDTO)
{
if (demandeFormation == null || demandeFormationDTO == null)
return null;
demandeFormation.Libelle = demandeFormationDTO.Libelle;
demandeFormation.Description = demandeFormationDTO.Description;
demandeFormation.DemandeRH = demandeFormationDTO.DemandeRH.Value;
demandeFormation.DateDemande = demandeFormationDTO.DateDemande.Value;
demandeFormation.Etat = demandeFormationDTO.EtatDemande;
demandeFormation.CommentaireRefus = demandeFormationDTO.CommentaireRefus;
demandeFormation.DateDerniereReponse = demandeFormationDTO.DateDerniereReponse;
demandeFormation.OrigineDemande = GetOrigineDemandeFormation(demandeFormationDTO.Origine);
return demandeFormation;
}
/// <summary>
/// Mettre à jour un objet Formation en fonction d'un objet FormationDTO.
/// </summary>
/// <param name="formation"></param>
/// <param name="formationDTO"></param>
/// <returns></returns>
public Formation SetFormation(Formation formation, FormationDTO formationDTO)
{
if (formation == null || formationDTO == null)
return null;
if (formationDTO.Id.HasValue)
formation.IdFormation = formationDTO.Id.Value;
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;
}
/// <summary>
/// Récupérer un objet Formation en fonction d'un objet FormationDetailsDTO.
/// </summary>
/// <param name="formationDetailsDTO"></param>
/// <returns></returns>
public Formation GetFormation(FormationDetailsDTO formationDetailsDTO)
{
if (formationDetailsDTO == null)
return null;
Formation formation = new Formation
{
Intitule = formationDetailsDTO.Intitule,
DateDebut = formationDetailsDTO.DateDebut.Value,
DateFin = formationDetailsDTO.DateFin.Value,
Organisme = formationDetailsDTO.Organisme,
EstCertifiee = formationDetailsDTO.EstCertifiee.Value,
//EstRealisee = formationDTO.EstRealisee.Value,
Origine = GetOrigineFormation(formationDetailsDTO.Origine),
Statut = GetStatutFormation(formationDetailsDTO.Statut),
};
if (formationDetailsDTO.Id.HasValue)
formation.IdFormation = formationDetailsDTO.Id.Value;
return formation;
}
/// <summary>
/// Mettre à jour la réponse d'un objet Engagement en fonction d'un objet EngagementDTO.
/// </summary>
/// <param name="engagement"></param>
/// <param name="engagementDTO"></param>
/// <returns></returns>
public 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;
}
}
}