|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
using EPAServeur.Context; |
|
|
|
|
using EPAServeur.Exceptions; |
|
|
|
|
using EPAServeur.IServices; |
|
|
|
|
using EPAServeur.Models.EP; |
|
|
|
|
using EPAServeur.Models.Formation; |
|
|
|
|
using IO.Swagger.DTO; |
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
@ -20,6 +21,11 @@ namespace EPAServeur.Services |
|
|
|
|
/// </summary> |
|
|
|
|
private readonly EpContext epContext; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Accès et service collaborateur |
|
|
|
|
/// </summary> |
|
|
|
|
private readonly ICollaborateurService collaborateurService; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Nombre d'éléments min à afficher par page |
|
|
|
|
/// </summary> |
|
|
|
@ -53,9 +59,10 @@ namespace EPAServeur.Services |
|
|
|
|
/// Constructeur de la classe FormationService |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="_epContext"></param> |
|
|
|
|
public FormationService(EpContext _epContext) |
|
|
|
|
public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService) |
|
|
|
|
{ |
|
|
|
|
epContext = _epContext; |
|
|
|
|
collaborateurService = _collaborateurService; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
@ -81,7 +88,12 @@ namespace EPAServeur.Services |
|
|
|
|
if (formation == null) |
|
|
|
|
throw new FormationNotFoundException(string.Format("Aucune formation trouvée avec l'id suivant: {0}.",idFormation)); |
|
|
|
|
|
|
|
|
|
return GetFormationDTO(formation); |
|
|
|
|
if (formation.ParticipationsFormation.Count == 0) |
|
|
|
|
return GetFormationDTO(formation); |
|
|
|
|
|
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(formation.ParticipationsFormation); |
|
|
|
|
|
|
|
|
|
return GetFormationDTO(formation, collaborateurDTOs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -375,7 +387,15 @@ namespace EPAServeur.Services |
|
|
|
|
if (!asc.HasValue) |
|
|
|
|
asc = defaultAsc; |
|
|
|
|
|
|
|
|
|
switch (columnName) |
|
|
|
|
if (string.IsNullOrWhiteSpace(columnName)) |
|
|
|
|
{ |
|
|
|
|
if (asc.Value) |
|
|
|
|
return query.OrderBy(p => p.Intitule); |
|
|
|
|
else |
|
|
|
|
return query.OrderByDescending(p => p.Intitule); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (columnName.ToLower()) |
|
|
|
|
{ |
|
|
|
|
case "intitule": |
|
|
|
|
if (asc.Value) |
|
|
|
@ -402,9 +422,6 @@ namespace EPAServeur.Services |
|
|
|
|
return query.OrderBy(p => p.EstCertifiee); |
|
|
|
|
else |
|
|
|
|
return query.OrderByDescending(p => p.EstCertifiee); |
|
|
|
|
//(A faire lorsque la gestion des participations aux formations sera terminée) |
|
|
|
|
//case "participants": |
|
|
|
|
// return query; |
|
|
|
|
default: |
|
|
|
|
if (asc.Value) |
|
|
|
|
return query.OrderBy(p => p.Intitule); |
|
|
|
@ -421,7 +438,7 @@ namespace EPAServeur.Services |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private IQueryable<Formation> IdStatutsFilter(IQueryable<Formation> query, List<int?> idStatuts) |
|
|
|
|
{ |
|
|
|
|
if (idStatuts != null && idStatuts.Count > 0) |
|
|
|
|
if (idStatuts != null && idStatuts.Count > 0 && idStatuts.First().HasValue) |
|
|
|
|
return query.Where(formation => idStatuts.Contains(formation.Statut.IdStatutFormation)); |
|
|
|
|
else |
|
|
|
|
return query; |
|
|
|
@ -523,7 +540,35 @@ namespace EPAServeur.Services |
|
|
|
|
Statut = GetStatutFormationDTO(formation.Statut), |
|
|
|
|
Mode = GetModeFormationDTO(formation.ModeFormation), |
|
|
|
|
Type = GetTypeFormationDTO(formation.TypeFormation), |
|
|
|
|
Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return formationDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récuperer un objet FormationDTO avec des participations en fonction d'un objet Formation et d'une liste de CollaborateurDTO |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="formation"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private FormationDTO GetFormationDTO(Formation formation, IEnumerable<CollaborateurDTO> collaborateurDTOs) |
|
|
|
|
{ |
|
|
|
|
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; |
|
|
|
@ -621,42 +666,120 @@ namespace EPAServeur.Services |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récuperer une liste de ParticipationFormationDTO en fonction d'une liste de ParticipationFormation |
|
|
|
|
/// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="typeFormation"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private List<ParticipationFormationDTO> GetParticipationsFormationDTO(List<ParticipationFormation> participationsFormation) |
|
|
|
|
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(List<ParticipationFormation> participationsFormation) |
|
|
|
|
{ |
|
|
|
|
if (participationsFormation.Count == 0) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
List<Guid?> guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); |
|
|
|
|
|
|
|
|
|
return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récuperer une liste de ParticipationFormationDTO en fonction d'une liste de ParticipationFormation et d'une liste de CollaborateurDTO |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="typeFormation"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private List<ParticipationFormationDTO> GetParticipationsFormationDTO(List<ParticipationFormation> participationsFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs) |
|
|
|
|
{ |
|
|
|
|
List<ParticipationFormationDTO> participationFormationDTOs; |
|
|
|
|
|
|
|
|
|
if (participationsFormation == null || participationsFormation.Count == 0) |
|
|
|
|
if (participationsFormation == null || participationsFormation.Count == 0 || collaborateurDTOs == null || !collaborateurDTOs.Any()) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation)).ToList(); |
|
|
|
|
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 ParticipationFormationDTO en fonction d'un objet ParticipationFormation |
|
|
|
|
/// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="participationFormation"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation) |
|
|
|
|
private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs) |
|
|
|
|
{ |
|
|
|
|
if (participationFormation == null) |
|
|
|
|
return null; |
|
|
|
|
ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO() |
|
|
|
|
{ |
|
|
|
|
Id = participationFormation.IdParticipationFormation, |
|
|
|
|
DateCreation = participationFormation.DateCreation, |
|
|
|
|
Intitule = participationFormation.Formation.Intitule, |
|
|
|
|
DateDebut= participationFormation.Formation.DateDebut, |
|
|
|
|
DateDebut = participationFormation.Formation.DateDebut, |
|
|
|
|
Statut = GetStatutFormationDTO(participationFormation.Formation.Statut), |
|
|
|
|
Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs), |
|
|
|
|
Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return participationFormationDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="participationFormation"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs) |
|
|
|
|
{ |
|
|
|
|
CollaborateurDTO collaborateur; |
|
|
|
|
|
|
|
|
|
if (participationFormation == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
if (collaborateurDTOs == null || !collaborateurDTOs.Any()) |
|
|
|
|
collaborateur = null; |
|
|
|
|
else |
|
|
|
|
collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur); |
|
|
|
|
|
|
|
|
|
return collaborateur; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="ep"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs) |
|
|
|
|
{ |
|
|
|
|
CollaborateurDTO collaborateur; |
|
|
|
|
CollaborateurDTO referent; |
|
|
|
|
|
|
|
|
|
if (ep == null) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
if (collaborateurDTOs == null || !collaborateurDTOs.Any()) |
|
|
|
|
{ |
|
|
|
|
collaborateur = null; |
|
|
|
|
referent = null; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
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 |
|
|
|
@ -677,6 +800,7 @@ namespace EPAServeur.Services |
|
|
|
|
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); |
|
|
|
|