|
|
|
@ -1,414 +0,0 @@ |
|
|
|
|
using EPAServeur.Exceptions; |
|
|
|
|
using EPAServeur.IServices; |
|
|
|
|
using IO.Swagger.ApiCollaborateur; |
|
|
|
|
using IO.Swagger.DTO; |
|
|
|
|
using IO.Swagger.ModelCollaborateur; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
namespace EPAServeur.Services |
|
|
|
|
{ |
|
|
|
|
public class ReferentService : IReferentService |
|
|
|
|
{ |
|
|
|
|
#region Variables |
|
|
|
|
// private readonly IReferentApi referentApi; |
|
|
|
|
private readonly ICollaborateurApi collaborateurApi; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Contructeurs |
|
|
|
|
public ReferentService(ICollaborateurApi _collaborateurApi) |
|
|
|
|
{ |
|
|
|
|
//referentApi = _referentApi; |
|
|
|
|
collaborateurApi = _collaborateurApi; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Méthodes Service |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un référent par son id |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="idReferent"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public ReferentDTO GetReferentById(Guid? idReferent) |
|
|
|
|
{ |
|
|
|
|
Collaborateur referent = collaborateurApi.ChercherCollabId(idReferent); |
|
|
|
|
|
|
|
|
|
if (referent == null) |
|
|
|
|
throw new ReferentNotFoundException(); |
|
|
|
|
|
|
|
|
|
return GetReferentDTO(referent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un référent par son id de manière asynchrone |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="idReferent"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<ReferentDTO> GetReferentByIdAsync(Guid? idReferent) |
|
|
|
|
{ |
|
|
|
|
Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(idReferent); |
|
|
|
|
|
|
|
|
|
if (referent == null) |
|
|
|
|
throw new ReferentNotFoundException(); |
|
|
|
|
|
|
|
|
|
return GetReferentDTO(referent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un référent en fonction d'un collaborateur |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="idCollaborateur"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public ReferentDTO GetReferentActuelCollaborateur(Guid? idCollaborateur) |
|
|
|
|
{ |
|
|
|
|
Collaborateur referent = collaborateurApi.ChercherRefActuelId(idCollaborateur); |
|
|
|
|
|
|
|
|
|
if (referent == null) |
|
|
|
|
throw new ReferentNotFoundException(); |
|
|
|
|
|
|
|
|
|
return GetReferentDTO(referent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un référent en fonction d'un collaborateur de manière asynchrone |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="idCollaborateur"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<ReferentDTO> GetReferentActuelCollaborateurAsync(Guid? idCollaborateur) |
|
|
|
|
{ |
|
|
|
|
Collaborateur referent = await collaborateurApi.ChercherRefActuelIdAsync(idCollaborateur); |
|
|
|
|
|
|
|
|
|
if (referent == null) |
|
|
|
|
throw new ReferentNotFoundException(); |
|
|
|
|
|
|
|
|
|
return GetReferentDTO(referent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère la liste des référents pour une agence |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="asc"></param> |
|
|
|
|
/// <param name="numPage"></param> |
|
|
|
|
/// <param name="parPAge"></param> |
|
|
|
|
/// <param name="fonctions"></param> |
|
|
|
|
/// <param name="idAgence"></param> |
|
|
|
|
/// <param name="idBU"></param> |
|
|
|
|
/// <param name="texte"></param> |
|
|
|
|
/// <param name="tri"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public IEnumerable<ReferentDTO> GetReferents(bool? asc, int? numPage, int? parPAge, List<string> fonctions, long? idAgence, long? idBU, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
|
|
////IEnumerable<Collaborateur> collaborateurs; // A changer (Sera utilisé pour récupérer la liste des référents par fonction |
|
|
|
|
//IEnumerable<Referent> referents = null; // A changer |
|
|
|
|
//IEnumerable<ReferentDTO> referentDTOs = null; // A changer |
|
|
|
|
////List<Guid?> ids = fonctions.Select(guid => (Guid?)Guid.Parse(guid)).ToList(); |
|
|
|
|
|
|
|
|
|
////collaborateurs = collaborateurApi.ChercherCollab(ids); |
|
|
|
|
//if (texte == null) |
|
|
|
|
// texte = ""; |
|
|
|
|
//else |
|
|
|
|
// texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
//int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
//int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
//if (idBU != null) |
|
|
|
|
//{ |
|
|
|
|
|
|
|
|
|
//} |
|
|
|
|
//else |
|
|
|
|
//{ |
|
|
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
//if (idAgence != null) |
|
|
|
|
//{ |
|
|
|
|
// try |
|
|
|
|
// { |
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
// catch (Exception ex) |
|
|
|
|
// { |
|
|
|
|
// throw; |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
//else |
|
|
|
|
//{ |
|
|
|
|
// try |
|
|
|
|
// { |
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
// catch (Exception ex) |
|
|
|
|
// { |
|
|
|
|
// throw; |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (referents == null) |
|
|
|
|
// return new List<ReferentDTO>(); |
|
|
|
|
|
|
|
|
|
//referentDTOs = referents.Where(referent => (referent.Nom + " " + referent.Prenom).ToLower().Contains(texte) || (referent.Prenom + " " + referent.Nom).ToLower().Contains(texte)).Select(referent => GetReferentDTO(referent)); |
|
|
|
|
|
|
|
|
|
//return referentDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère la liste des référents pour une agence de manière asynchrone |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="asc"></param> |
|
|
|
|
/// <param name="numPage"></param> |
|
|
|
|
/// <param name="parPAge"></param> |
|
|
|
|
/// <param name="fonctions"></param> |
|
|
|
|
/// <param name="idAgence"></param> |
|
|
|
|
/// <param name="idBU"></param> |
|
|
|
|
/// <param name="texte"></param> |
|
|
|
|
/// <param name="tri"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<ReferentDTO>> GetReferentsAsync(bool? asc, int? numPage, int? parPAge, List<string> fonctions, long? idAgence, long? idBU, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
|
|
//IEnumerable<Referent> referents = null ; // A changer |
|
|
|
|
//IEnumerable<ReferentDTO> referentDTOs = null; // A changer |
|
|
|
|
|
|
|
|
|
//if (texte == null) |
|
|
|
|
// texte = ""; |
|
|
|
|
//else |
|
|
|
|
// texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
//int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
//int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
//if (idBU != null) |
|
|
|
|
//{ |
|
|
|
|
|
|
|
|
|
//} |
|
|
|
|
//else |
|
|
|
|
//{ |
|
|
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
//if (idAgence != null) |
|
|
|
|
//{ |
|
|
|
|
// try |
|
|
|
|
// { |
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
// catch (Exception ex) |
|
|
|
|
// { |
|
|
|
|
// throw; |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
//else |
|
|
|
|
//{ |
|
|
|
|
// try |
|
|
|
|
// { |
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
// catch (Exception ex) |
|
|
|
|
// { |
|
|
|
|
// throw; |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (referents == null) |
|
|
|
|
// return new List<ReferentDTO>(); |
|
|
|
|
|
|
|
|
|
//referentDTOs = referents.Where(referent => (referent.Nom + " " + referent.Prenom).ToLower().Contains(texte) || (referent.Prenom + " " + referent.Nom).ToLower().Contains(texte)).Select(referent => GetReferentDTO(referent)); |
|
|
|
|
|
|
|
|
|
//return referentDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère la liste des référents pour un collaborateur |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="asc"></param> |
|
|
|
|
/// <param name="idCollaborateur"></param> |
|
|
|
|
/// <param name="numPage"></param> |
|
|
|
|
/// <param name="parPAge"></param> |
|
|
|
|
/// <param name="texte"></param> |
|
|
|
|
/// <param name="tri"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public IEnumerable<ReferentDTO> GetReferentsByCollaborateur(bool? asc, Guid? idCollaborateur, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Collaborateur> referents; |
|
|
|
|
IEnumerable<ReferentDTO> referentDTOs; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
|
else |
|
|
|
|
texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idCollaborateur == null) |
|
|
|
|
return new List<ReferentDTO>(); |
|
|
|
|
|
|
|
|
|
Collaborateur collaborateur = collaborateurApi.ChercherCollabId(idCollaborateur); |
|
|
|
|
|
|
|
|
|
if (collaborateur == null) |
|
|
|
|
throw new CollaborateurNotFoundException(); |
|
|
|
|
|
|
|
|
|
referents = collaborateurApi.ChercherRefCollabId(idCollaborateur); |
|
|
|
|
|
|
|
|
|
if (referents == null) |
|
|
|
|
return new List<ReferentDTO>(); |
|
|
|
|
|
|
|
|
|
referentDTOs = referents.Where(referent => (referent.Nom + " " + referent.Prenom).ToLower().Contains(texte) || (referent.Prenom + " " + referent.Nom).ToLower().Contains(texte)).Select(referent => GetReferentDTO(referent)); |
|
|
|
|
|
|
|
|
|
return referentDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère la liste des référents pour un collaborateur de manère asynchrone |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="asc"></param> |
|
|
|
|
/// <param name="idCollaborateur"></param> |
|
|
|
|
/// <param name="numPage"></param> |
|
|
|
|
/// <param name="parPAge"></param> |
|
|
|
|
/// <param name="texte"></param> |
|
|
|
|
/// <param name="tri"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<IEnumerable<ReferentDTO>> GetReferentsByCollaborateurAsync(bool? asc, Guid? idCollaborateur, int? numPage, int? parPAge, string texte, string tri) |
|
|
|
|
{ |
|
|
|
|
IEnumerable<Collaborateur> referents; |
|
|
|
|
IEnumerable<ReferentDTO> referentDTOs; |
|
|
|
|
|
|
|
|
|
if (texte == null) |
|
|
|
|
texte = ""; |
|
|
|
|
else |
|
|
|
|
texte = texte.ToLower(); |
|
|
|
|
|
|
|
|
|
int skip = (numPage.Value - 1) * parPAge.Value; |
|
|
|
|
int take = parPAge.Value; |
|
|
|
|
|
|
|
|
|
if (idCollaborateur == null) |
|
|
|
|
return new List<ReferentDTO>(); |
|
|
|
|
|
|
|
|
|
Collaborateur collaborateur = await collaborateurApi.ChercherCollabIdAsync(idCollaborateur); |
|
|
|
|
|
|
|
|
|
if (collaborateur == null) |
|
|
|
|
throw new CollaborateurNotFoundException(); |
|
|
|
|
|
|
|
|
|
referents = await collaborateurApi.ChercherRefCollabIdAsync(idCollaborateur); |
|
|
|
|
|
|
|
|
|
if (referents == null) |
|
|
|
|
return new List<ReferentDTO>(); |
|
|
|
|
|
|
|
|
|
referentDTOs = referents.Where(referent => (referent.Nom + " " + referent.Prenom).ToLower().Contains(texte) || (referent.Prenom + " " + referent.Nom).ToLower().Contains(texte)).Select(referent => GetReferentDTO(referent)); |
|
|
|
|
|
|
|
|
|
return referentDTOs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region Méthodes Privées |
|
|
|
|
|
|
|
|
|
#region Object to DTO |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet AgenceDTO en fonction d'un objet Agence |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="agence"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private AgenceDTO GetAgenceDTO(Agence agence) |
|
|
|
|
{ |
|
|
|
|
if (agence == null) |
|
|
|
|
return null; |
|
|
|
|
AgenceDTO agenceDTO = new AgenceDTO() |
|
|
|
|
{ |
|
|
|
|
Id = agence.Id, |
|
|
|
|
Nom = agence.Nom, |
|
|
|
|
Bu = new List<BusinessUnitDTO>() |
|
|
|
|
}; |
|
|
|
|
agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO() |
|
|
|
|
{ |
|
|
|
|
Id = bu.Id, |
|
|
|
|
Nom = bu.Nom |
|
|
|
|
}).ToList(); |
|
|
|
|
return agenceDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet BusinessUnitDTO en fonction d'un objet BU |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="businessUnit"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit) |
|
|
|
|
{ |
|
|
|
|
if (businessUnit == null) |
|
|
|
|
return null; |
|
|
|
|
BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO() |
|
|
|
|
{ |
|
|
|
|
Id = businessUnit.Id, |
|
|
|
|
Nom = businessUnit.Nom, |
|
|
|
|
Agence = GetAgenceDTO(businessUnit.Agence) |
|
|
|
|
}; |
|
|
|
|
return businessUnitDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet CollaborateurDTO en fonction d'un objet Collaborateur |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="collaborateur"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur) |
|
|
|
|
{ |
|
|
|
|
CollaborateurDTO collaborateurDTO = new CollaborateurDTO() |
|
|
|
|
{ |
|
|
|
|
Id = collaborateur.Id, |
|
|
|
|
Prenom = collaborateur.Prenom, |
|
|
|
|
Nom = collaborateur.Nom, |
|
|
|
|
MailApside = collaborateur.MailApside, |
|
|
|
|
DateArrivee = collaborateur.DateArrivee, |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit); |
|
|
|
|
collaborateurDTO.Referent = GetReferentDTO(collaborateur.Referent); |
|
|
|
|
return collaborateurDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Récupère un objet ReferentDTO en fonction d'un objet Referent |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="referent"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
private ReferentDTO GetReferentDTO(Collaborateur referent) |
|
|
|
|
{ |
|
|
|
|
if (referent == null) |
|
|
|
|
return null; |
|
|
|
|
ReferentDTO referentDTO = new ReferentDTO() |
|
|
|
|
{ |
|
|
|
|
Id = referent.Id, |
|
|
|
|
Prenom = referent.Prenom, |
|
|
|
|
Nom = referent.Nom, |
|
|
|
|
MailApside = referent.MailApside |
|
|
|
|
}; |
|
|
|
|
return referentDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region DTO to Object |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |