using EPAServeur.Context; using EPAServeur.Exceptions; using EPAServeur.IServices; using EPAServeur.Models.EP; 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 EpDetailsService : IEpDetailsService { private EpContext context; private ITransformDTO transformDTO; private ICollaborateurService collaborateurService; public EpDetailsService(EpContext context, ITransformDTO transformDTO, ICollaborateurService collaborateurService) { this.context = context; this.transformDTO = transformDTO; this.collaborateurService = collaborateurService; } public async Task GetEp(long? id) { Ep ep = await context.Ep .Include(ep => ep.Engagements) .Include(ep => ep.Participants) .Include(ep => ep.CommentairesAssistant) .Include(ep => ep.DemandeDelegation) .Include(ep => ep.RdvEntretien).ThenInclude(rdv => rdv.TypeEntretien) .Include(ep => ep.PropositionsRDV).ThenInclude(rdv => rdv.TypeEntretien) .Include(ep => ep.ChoixTypeEntretien).ThenInclude( c => c.TypeEntretien) .Include(ep => ep.Objectifs) .Include(ep => ep.ObjectifsPrecedents) .Include(ep => ep.DemandeEPI) .FirstOrDefaultAsync(ep => ep.IdEP.Equals(id)); if (ep == null) throw new EpNotFoundException(); //ajouter tous les guids liés à l'EP et aux attributs de l'EP List guids = new List { ep.IdCollaborateur }; if (ep.IdReferent.HasValue) guids.Add(ep.IdCollaborateur); if (ep.Participants != null && ep.Participants.Any()) guids.AddRange(ep.Participants.SelectMany(p => new[] { (Guid?)p.IdParticipant })); if (ep.CommentairesAssistant != null && ep.CommentairesAssistant.Any()) guids.AddRange(ep.CommentairesAssistant.SelectMany(p => new[] { (Guid?)p.IdAssistant })); if (ep.DemandeDelegation != null) guids.Add(ep.DemandeDelegation.IdReferent); if (ep.DemandeEPI != null && ep.DemandeEPI.IdReferent != null) guids.Add(ep.DemandeEPI.IdReferent); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); EpDTO epDTO = transformDTO.EpToEpDetails(ep, collaborateurDTOs); return epDTO; } public void RappelSignature(long? idEp) { throw new NotImplementedException(); } public Task SaisirEPCollaborateur(Guid? idCollaborateur) { throw new NotImplementedException(); } public Task SaisirEPReferent(long? idEp) { throw new NotImplementedException(); } public void SupprimerDonneesEPCollaborateur(Guid? idCollaborateur) { throw new NotImplementedException(); } public void SupprimerEP(long? idEp) { throw new NotImplementedException(); } public Task UpdateEP(long? idEp, EpDTO ep) { throw new NotImplementedException(); } public Task UpdateSaisie(long? idEp, EpDTO ep) { throw new NotImplementedException(); } } }