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.
178 lines
5.2 KiB
178 lines
5.2 KiB
using EPAServeur.Context;
|
|
using EPAServeur.IServices;
|
|
using IO.Swagger.ApiCollaborateur;
|
|
using IO.Swagger.DTO;
|
|
using IO.Swagger.ModelCollaborateur;
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EPAServeur.Services
|
|
{
|
|
public class CollaborateurService : ICollaborateurService
|
|
{
|
|
private readonly ICollaborateurApi collaborateurApi;
|
|
|
|
public CollaborateurService(ICollaborateurApi _collaborateurApi)
|
|
{
|
|
collaborateurApi = _collaborateurApi;
|
|
}
|
|
|
|
|
|
public CollaborateurDTO GetCollaborateurById(Guid? id)
|
|
{
|
|
Collaborateur collaborateur = collaborateurApi.ChercherCollabId(id);
|
|
if (collaborateur == null)
|
|
return null;
|
|
return GetCollaborateurDTO(collaborateur);
|
|
}
|
|
|
|
public CollaborateurDTO GetCollaborateurByMail(string mail)
|
|
{
|
|
Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail);
|
|
if (collaborateur == null)
|
|
return null;
|
|
return GetCollaborateurDTO(collaborateur);
|
|
}
|
|
|
|
|
|
public IEnumerable<CollaborateurDTO> GetCollaborateurs(bool? asc, int? numPage, int? parPage, List<string> fonctions, int? idAgence, int? idBU, string texte, string tri)
|
|
{
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
IEnumerable<Collaborateur> collaborateurs;
|
|
IEnumerable<CollaborateurDTO> collaborateursDTO;
|
|
if(idBU != null)
|
|
collaborateurs = collaborateurApi.ChercherCollabBU(idBU);
|
|
else if( idAgence != null)
|
|
collaborateurs = collaborateurApi.ChercherCollabAgence(idAgence);
|
|
else
|
|
collaborateurs = collaborateurApi.ChercherCollab();
|
|
if (collaborateurs == null)
|
|
return new List<CollaborateurDTO>();
|
|
int skip = (numPage.Value - 1) * parPage.Value;
|
|
int take = parPage.Value;
|
|
collaborateursDTO = (from c in collaborateurs
|
|
where (c.Nom + " " + c.Prenom).ToLower().Contains(texte) || (c.Prenom + " " + c.Nom).ToLower().Contains(texte)
|
|
select GetCollaborateurDTO(c)).Skip(skip).Take(take);
|
|
|
|
return collaborateursDTO;
|
|
}
|
|
|
|
public IEnumerable<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri)
|
|
{
|
|
if (texte == null)
|
|
texte = "";
|
|
else
|
|
texte = texte.ToLower();
|
|
Collaborateur referent = collaborateurApi.ChercherCollabId(idReferent);
|
|
if (referent == null)
|
|
return null;
|
|
IEnumerable<Collaborateur> collaborateurs = collaborateurApi.ChercherCollabRef(idReferent);
|
|
int skip = (numPage.Value - 1) * parPage.Value;
|
|
int take = parPage.Value;
|
|
IEnumerable<CollaborateurDTO> collaborateursDTO = (from c in collaborateurs
|
|
where (c.Nom + " " + c.Prenom).ToLower().Contains(texte) || (c.Prenom + " " + c.Nom).ToLower().Contains(texte)
|
|
select GetCollaborateurDTO(c)).Skip(skip).Take(take);
|
|
return collaborateursDTO;
|
|
}
|
|
|
|
public ProfilDTO GetProfilByMail(string mail)
|
|
{
|
|
Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail);
|
|
if (collaborateur == null)
|
|
return null;
|
|
return GetProfilDTO(collaborateur);
|
|
}
|
|
|
|
public ProfilDTO GetProfilById(Guid? idCollaborateur)
|
|
{
|
|
Collaborateur collaborateur = collaborateurApi.ChercherCollabId(idCollaborateur);
|
|
if (collaborateur == null)
|
|
return null;
|
|
return GetProfilDTO(collaborateur);
|
|
}
|
|
|
|
//Object to DTO
|
|
private ProfilDTO GetProfilDTO(Collaborateur collaborateur)
|
|
{
|
|
ProfilDTO profilDTO = new ProfilDTO()
|
|
{
|
|
Id = collaborateur.Id,
|
|
DateArrivee = collaborateur.DateArrivee,
|
|
MailApside = collaborateur.MailApside,
|
|
Nom = collaborateur.Nom,
|
|
Prenom = collaborateur.Prenom,
|
|
BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit)
|
|
};
|
|
return profilDTO;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|