Implémentation de la récupération des participants à un EP

develop
Yanaël GRETTE 4 years ago
parent daab188c86
commit b48458e2d0
  1. 18
      EPAServeur.Tests/Services/EpDetailsServiceTests.cs
  2. 39
      EPAServeur/Context/DataSeeder.cs
  3. 3
      EPAServeur/IServices/ITransformDTO.cs
  4. 2
      EPAServeur/Models/EP/ParticipationEP.cs
  5. 9
      EPAServeur/Services/EpDetailsService.cs
  6. 49
      EPAServeur/Services/TransformDTO.cs

@ -108,6 +108,24 @@ namespace EPAServeur.Tests.Services
#endregion #endregion
#region Récupérer EP avec participant EP #region Récupérer EP avec participant EP
[TestCase(1,0)]
[TestCase(3,2)]
[TestCase(5,1)]
[TestCase(11,2)]
public async Task GetEpById_GetParticipantEP(long idEP, int count)
{
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
EpDTO epDTO = await epDetailsService.GetEp(idEP);
if (count == 0)
{
Assert.IsNull(epDTO.Participants);
}
else
{
Assert.IsNotNull(epDTO.Participants);
Assert.AreEqual(count, epDTO.Participants.Count);
}
}
#endregion #endregion
#region Récupérer EP avec RDV entretiens #region Récupérer EP avec RDV entretiens

@ -85,9 +85,12 @@ namespace EPAServeur.Context
public static void AddEp(EpContext epContext) public static void AddEp(EpContext epContext)
{ {
Engagement eg1, eg2, eg3, eg4; Engagement eg1, eg2, eg3, eg4;
ParticipationEP p1, p2, p3, p4, p5;
//Ep en cours //Ep en cours
Ep epEnCours1, epEnCours2, epEnCours3, epEnCours4, epEnCours5, epEnCours6, epEnCours7, epEnCours8, epEnCours9; Ep epEnCours1, epEnCours2, epEnCours3, epEnCours4, epEnCours5, epEnCours6, epEnCours7, epEnCours8, epEnCours9;
//Tours
epEnCours1 = new Ep() epEnCours1 = new Ep()
{ {
@ -130,6 +133,20 @@ namespace EPAServeur.Context
IdCollaborateur = new Guid("b5254c6c-7caa-435f-a4bb-e0cf92559832"), IdCollaborateur = new Guid("b5254c6c-7caa-435f-a4bb-e0cf92559832"),
Obligatoire = false, Obligatoire = false,
}; };
p1 = new ParticipationEP()
{
Ep = epEnCours3,
IdParticipant = new Guid("eb8b0f33-f529-4985-861e-1207f3312bb5"),
EstPermanente = false
};
p2 = new ParticipationEP()
{
Ep = epEnCours3,
IdParticipant = new Guid("d4fc247b-015a-44d6-8f3e-a52f0902d2bf"),
EstPermanente = false
};
epEnCours3.Participants = new List<ParticipationEP>(new[] { p1, p2 });
epContext.Ep.Add(epEnCours3); epContext.Ep.Add(epEnCours3);
epEnCours4 = new Ep() epEnCours4 = new Ep()
@ -158,6 +175,13 @@ namespace EPAServeur.Context
IdCollaborateur = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"), IdCollaborateur = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"),
Obligatoire = true, Obligatoire = true,
}; };
p3 = new ParticipationEP()
{
Ep = epEnCours5,
IdParticipant = new Guid("d4fc247b-015a-44d6-8f3e-a52f0902d2bf"),
EstPermanente = false
};
epEnCours5.Participants = new List<ParticipationEP>(new[] { p3 });
epContext.Ep.Add(epEnCours5); epContext.Ep.Add(epEnCours5);
epEnCours6 = new Ep() epEnCours6 = new Ep()
@ -289,6 +313,19 @@ namespace EPAServeur.Context
IdCollaborateur = new Guid("e7820f92-eab1-42f5-ae96-5c16e71ff1e6"), IdCollaborateur = new Guid("e7820f92-eab1-42f5-ae96-5c16e71ff1e6"),
Obligatoire = false, Obligatoire = false,
}; };
p4 = new ParticipationEP()
{
Ep = epSigne2,
IdParticipant = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"),
EstPermanente = false
};
p5 = new ParticipationEP()
{
Ep = epSigne2,
IdParticipant = new Guid("eb8b0f33-f529-4985-861e-1207f3312bb5"),
EstPermanente = false
};
epSigne2.Participants = new List<ParticipationEP>(new[] { p4, p5 });
epContext.Ep.Add(epSigne2); epContext.Ep.Add(epSigne2);

@ -72,7 +72,8 @@ namespace EPAServeur.IServices
// Récupération DetailsEP // Récupération DetailsEP
EpDTO EpToEpDetails(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs); EpDTO EpToEpDetails(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs);
List<EngagementDTO> GetEngagementDTOs(Ep ep); List<EngagementDTO> GetEngagementDTOs(List<Engagement> engagements);
List<ParticipationEPDTO> GetParticipantsDTO(List<ParticipationEP> participants, IEnumerable<CollaborateurDTO> collaborateurDTOs);
DemandeEPIDTO GetDemandeEPIDTO(DemandeEPI demande, IEnumerable<CollaborateurDTO> collaborateurDTOs); DemandeEPIDTO GetDemandeEPIDTO(DemandeEPI demande, IEnumerable<CollaborateurDTO> collaborateurDTOs);
AugmentationSalaireDTO GetAugmentationSalaireDTO(AugmentationSalaire augmentation); AugmentationSalaireDTO GetAugmentationSalaireDTO(AugmentationSalaire augmentation);
DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable<CollaborateurDTO> collaborateurDTOs); DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demandeDelegation, IEnumerable<CollaborateurDTO> collaborateurDTOs);

@ -18,7 +18,7 @@ namespace EPAServeur.Models.EP
/// <summary> /// <summary>
/// Id du collaborateur participant à l’EP /// Id du collaborateur participant à l’EP
/// </summary> /// </summary>
public string IdParticipant { get; set; } public Guid IdParticipant { get; set; }
/// <summary> /// <summary>
/// Indique si la participation est juste une participation d’un EP en cours ou des prochains EP en plus /// Indique si la participation est juste une participation d’un EP en cours ou des prochains EP en plus

@ -2,7 +2,6 @@
using EPAServeur.Exceptions; using EPAServeur.Exceptions;
using EPAServeur.IServices; using EPAServeur.IServices;
using EPAServeur.Models.EP; using EPAServeur.Models.EP;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO; using IO.Swagger.DTO;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
@ -27,7 +26,10 @@ namespace EPAServeur.Services
public async Task<EpDTO> GetEp(long id) public async Task<EpDTO> GetEp(long id)
{ {
Ep ep = await context.Ep.Include(ep => ep.Engagements).FirstOrDefaultAsync(ep => ep.IdEP.Equals(id)); Ep ep = await context.Ep
.Include(ep => ep.Engagements)
.Include(ep => ep.Participants)
.FirstOrDefaultAsync(ep => ep.IdEP.Equals(id));
if (ep == null) if (ep == null)
throw new EpNotFoundException(); throw new EpNotFoundException();
@ -36,7 +38,8 @@ namespace EPAServeur.Services
guids.Add(ep.IdCollaborateur); guids.Add(ep.IdCollaborateur);
if (ep.IdReferent.HasValue) if (ep.IdReferent.HasValue)
guids.Add(ep.IdCollaborateur); guids.Add(ep.IdCollaborateur);
if (ep.Participants != null && ep.Participants.Any())
guids.AddRange(ep.Participants.SelectMany(p => new[] { (Guid?)p.IdParticipant }));
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);

@ -61,7 +61,8 @@ namespace EPAServeur.Services
Statut = ep.Statut, Statut = ep.Statut,
Type = ep.TypeEP, Type = ep.TypeEP,
Cv = ep.CV, Cv = ep.CV,
Engagements = GetEngagementDTOs(ep) Engagements = GetEngagementDTOs(ep.Engagements),
Participants = GetParticipantsDTO(ep.Participants, collaborateurDTOs)
}; };
} }
@ -295,11 +296,11 @@ namespace EPAServeur.Services
return engagementDTO; return engagementDTO;
} }
public List<EngagementDTO> GetEngagementDTOs(Ep ep) public List<EngagementDTO> GetEngagementDTOs(List<Engagement> engagements)
{ {
if (ep.Engagements == null || ep.Engagements.Count == 0) if (engagements == null || engagements.Count == 0)
return null; return null;
return ep.Engagements.Select(engagment => GetEngagementDTO(engagment, null, false)).ToList(); return engagements.Select(engagment => GetEngagementDTO(engagment, null, false)).ToList();
} }
public TypeEntretienDTO GetEntretienDTO(ChoixTypeEntretien choixTypeEntretien) public TypeEntretienDTO GetEntretienDTO(ChoixTypeEntretien choixTypeEntretien)
@ -540,14 +541,38 @@ namespace EPAServeur.Services
return origineFormationDTO; return origineFormationDTO;
} }
/// <summary> public List<ParticipationEPDTO> GetParticipantsDTO(List<ParticipationEP> participants, IEnumerable<CollaborateurDTO> collaborateurDTOs)
/// 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. if (participants == null || !participants.Any())
/// </summary> return null;
/// <param name="participationFormation"></param> List<ParticipationEPDTO> participantsDTO = new List<ParticipationEPDTO>();
/// <param name="collaborateurDTOs"></param> foreach(ParticipationEP p in participants)
/// <returns></returns> {
public ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs) CollaborateurDTO c = collaborateurDTOs.FirstOrDefault( c => c.Id.Equals(p.IdParticipant));
if(c != null)
{
participantsDTO.Add(new ParticipationEPDTO()
{
Id = p.IdParticipationEP,
EstPermanente = p.EstPermanente,
IdParticipant = c.Id,
Participant = c.Nom + " " + c.Prenom
});
}
}
if (participantsDTO.Any())
return participantsDTO;
return null;
}
/// <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()) if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null; return null;

Loading…
Cancel
Save