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

99 lines
2.8 KiB

using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.IServices;
using EPAServeur.Models.EP;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
using IO.Swagger.ModelCollaborateur;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Services
{
public class DemandeDelegationService : IDemandeDelegationService
{
#region variables
private readonly EpContext context;
private static ICollaborateurApi collaborateurAPI;
#endregion
#region constructeur
public DemandeDelegationService(ICollaborateurApi _collaborateurApi, EpContext _context)
{
context = _context;
collaborateurAPI = _collaborateurApi;
}
#endregion
#region services async
public async Task<IEnumerable<DemandeDelegationDTO>> RecupererDemandesDelegation(Guid? idReferent)
{
Collaborateur referent = await collaborateurAPI.ChercherCollabIdAsync(idReferent);
if (referent == null)
throw new ReferentNotFoundException();
CollaborateurDTO referentDTO = GetCollaborateurDTO(referent);
//var tasks = context.DemandeDelegations.Where( d => d.IdReferent.Equals(idReferent) && d.EtatDemande.Equals(EtatDemande.EnAttente)).Select()
var tasks = from demandeDelegation in context.DemandeDelegations.Include( d => d.Ep)
where demandeDelegation.IdReferent.Equals(idReferent) && demandeDelegation.EtatDemande.Equals(EtatDemande.EnAttente)
select GetDemandeDelegationDTO(demandeDelegation, referentDTO) ;
return await Task.WhenAll(tasks);
}
public async Task<DemandeDelegationDTO> UpdateDemandeDelegation(long id, DemandeDelegationDTO demandeDelegationDTO)
{
throw new NotImplementedException();
}
#endregion
#region
private static CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur)
{
return new CollaborateurDTO()
{
Id = collaborateur.Id,
Nom = collaborateur.Nom,
Prenom = collaborateur.Prenom,
};
}
private static async Task<EpInformationDTO> GetEpInformationDTO(Ep ep)
{
return new EpInformationDTO()
{
Id = ep.IdEP,
Collaborateur = GetCollaborateurDTO(await collaborateurAPI.ChercherCollabIdAsync(ep.IdCollaborateur)),
DatePrevisionnelle = ep.DatePrevisionnelle,
Statut = ep.Statut,
Type = ep.TypeEP,
Obligatoire = ep.Obligatoire,
};
}
private static async Task<DemandeDelegationDTO> GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent )
{
return new DemandeDelegationDTO()
{
Id = demande.IdDemandeDelegation,
DateDemande = demande.DateDemande,
EtatDemande = demande.EtatDemande,
Referent = referent,
RaisonDemande = demande.RaisonDemande,
Ep = await GetEpInformationDTO( demande.Ep)
};
}
#endregion
}
}