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/EpDetailsService.cs

94 lines
2.7 KiB

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<EpDTO> 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)
.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<Guid?> guids = new List<Guid?>();
guids.Add(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);
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
EpDTO epDTO = transformDTO.EpToEpDetails(ep, collaborateurDTOs);
return epDTO;
}
public void RappelSignature(long idEp)
{
throw new NotImplementedException();
}
public Task<EpDTO> SaisirEPCollaborateur(Guid? idCollaborateur)
{
throw new NotImplementedException();
}
public Task<EpDTO> SaisirEPReferent(long idEp)
{
throw new NotImplementedException();
}
public void SupprimerDonneesEPCollaborateur(Guid? idCollaborateur)
{
throw new NotImplementedException();
}
public void SupprimerEP(long idEp)
{
throw new NotImplementedException();
}
public Task<EpDTO> UpdateEP(long idEp, EpDTO ep)
{
throw new NotImplementedException();
}
public Task<EpDTO> UpdateSaisie(long idEp, EpDTO ep)
{
throw new NotImplementedException();
}
}
}