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.
146 lines
4.0 KiB
146 lines
4.0 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 List<CollaborateurDTO> GetCollaborateurs()
|
|
{
|
|
List<Collaborateur> collaborateurs = collaborateurApi.ChercherCollab();
|
|
List<CollaborateurDTO> collaborateursDTO = (from c in collaborateurs
|
|
select GetCollaborateurDTO(c)).ToList();
|
|
//List<CollaborateurDTO> collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList();
|
|
|
|
return collaborateursDTO;
|
|
}
|
|
|
|
public List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idReferent)
|
|
{
|
|
List<Collaborateur> collaborateurs = collaborateurApi.ChercherCollabRef(idReferent);
|
|
List<CollaborateurDTO> collaborateursDTO = (from c in collaborateurs
|
|
select GetCollaborateurDTO(c)).ToList();
|
|
//List<CollaborateurDTO> collaborateursDTO = collaborateurs.Select(c => GetCollaborateurDTO(c)).ToList();
|
|
|
|
return collaborateursDTO;
|
|
}
|
|
|
|
public ProfilDTO GetProfilByMail(string mail)
|
|
{
|
|
Collaborateur collaborateur = collaborateurApi.ChercherCollabMail(mail);
|
|
if (collaborateur == null)
|
|
return null;
|
|
return GetProfilDTO(collaborateur);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
//Object to DTO
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|