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.
253 lines
7.6 KiB
253 lines
7.6 KiB
using EPAServeur.IServices;
|
|
using IO.Swagger.ApiCollaborateur;
|
|
using IO.Swagger.DTO;
|
|
using IO.Swagger.ModelCollaborateur;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace EPAServeur.Services
|
|
{
|
|
public class ReferentService : IReferentService
|
|
{
|
|
#region Variables
|
|
private readonly IReferentApi referentApi;
|
|
|
|
#endregion
|
|
|
|
#region Contructeurs
|
|
public ReferentService(IReferentApi _referentApi)
|
|
{
|
|
referentApi = _referentApi;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Méthodes Service
|
|
|
|
/// <summary>
|
|
/// Récupère un référent par son id
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public ReferentDTO GetReferentById(Guid? id)
|
|
{
|
|
Referent referent = referentApi.ChercherRefId(id);
|
|
if (referent == null)
|
|
return null;
|
|
|
|
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)
|
|
{
|
|
Referent referent = referentApi.ChercherRefActuelCollabId(idCollaborateur);
|
|
|
|
if (referent == null)
|
|
return null;
|
|
|
|
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)
|
|
{
|
|
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<Referent> 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>();
|
|
|
|
|
|
referents = referentApi.ChercherRefCollabId(idCollaborateur);
|
|
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(Referent 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
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|