Récupération de la liste des collaborateurs 'simple' (sans trier)

master
Yanaël GRETTE 4 years ago
parent 96c3cc579d
commit 0506fa42a7
  1. 9
      Controllers/CollaborateursApi.cs
  2. 2
      IServices/ICollaborateurService.cs
  3. 98
      Services/CollaborateurService.cs

@ -130,7 +130,7 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpGet]
[Route("/api/collaborateurs")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetCollaborateurs")]
[SwaggerResponse(statusCode: 200, type: typeof(List<CollaborateurDTO>), description: "OK")]
@ -138,17 +138,16 @@ namespace IO.Swagger.Controllers
public virtual IActionResult GetCollaborateurs([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]List<string> fonctions, [FromQuery]int? idAgence, [FromQuery]int? idBU, [FromQuery]string texte, [FromQuery]string tri)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(List<CollaborateurDTO>));
return StatusCode(200, collaborateurService.GetCollaborateurs());
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
string exampleJson = null;
/*string exampleJson = null;
exampleJson = "[ {\n \"businessUnit\" : {\n \"agence\" : {\n \"bu\" : [ null, null ],\n \"id\" : 6.027456183070403,\n \"nom\" : \"nom\"\n },\n \"id\" : 0.8008281904610115,\n \"nom\" : \"nom\"\n },\n \"mailApside\" : \"\",\n \"dateArrivee\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateDepart\" : \"2000-01-23T04:56:07.000+00:00\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\"\n}, {\n \"businessUnit\" : {\n \"agence\" : {\n \"bu\" : [ null, null ],\n \"id\" : 6.027456183070403,\n \"nom\" : \"nom\"\n },\n \"id\" : 0.8008281904610115,\n \"nom\" : \"nom\"\n },\n \"mailApside\" : \"\",\n \"dateArrivee\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"dateDepart\" : \"2000-01-23T04:56:07.000+00:00\",\n \"nom\" : \"nom\",\n \"prenom\" : \"prenom\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<CollaborateurDTO>>(exampleJson)
: default(List<CollaborateurDTO>); //TODO: Change the data returned
return new ObjectResult(example);
return new ObjectResult(example);*/
}
/// <summary>

@ -16,8 +16,10 @@ namespace EPAServeur.IServices
List<CollaborateurDTO> GetCollaborateurs();
List<CollaborateurDTO> GetCollaborateursByReferent(Guid? idRefent);
//Object to DTO
CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur);
BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit);
AgenceDTO GetAgenceDTO(Agence agence);
ReferentDTO GetReferentDTO(Collaborateur referent);
}
}

@ -7,6 +7,7 @@ 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
@ -20,64 +21,81 @@ namespace EPAServeur.Services
collaborateurApi = _collaborateurApi;
}
public CollaborateurDTO GetCollaborateurById(Guid? id)
//
public AgenceDTO GetAgenceDTO(Agence agence)
{
Collaborateur collaborateur = collaborateurApi.ChercherCollabId(id);
if (collaborateur == null)
if (agence == null)
return null;
CollaborateurDTO collaborateurDTO = new CollaborateurDTO()
AgenceDTO agenceDTO = new AgenceDTO()
{
Id = collaborateur.Id,
Prenom = collaborateur.Prenom,
Nom = collaborateur.Nom,
MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee,
Id = agence.Id,
Nom = agence.Nom,
Bu = new List<BusinessUnitDTO>()
};
collaborateurDTO.BusinessUnit = new BusinessUnitDTO()
foreach(BU bu in agence.Bus)
{
Id = collaborateur.BusinessUnit.Id,
Nom = collaborateur.BusinessUnit.Nom,
Agence = new AgenceDTO()
agenceDTO.Bu.Add(new BusinessUnitDTO()
{
Id = collaborateur.BusinessUnit.Agence.Id,
Nom = collaborateur.BusinessUnit.Agence.Nom
}
};
collaborateurDTO.Referent = new ReferentDTO()
Id = bu.Id,
Nom = bu.Nom
});
}
return agenceDTO;
}
public BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit)
{
if (businessUnit == null)
return null;
BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO()
{
Id = collaborateur.Referent.Id,
Prenom = collaborateur.Referent.Prenom,
Nom = collaborateur.Referent.Nom,
MailApside = collaborateur.Referent.MailApside
Id = businessUnit.Id,
Nom = businessUnit.Nom,
Agence = GetAgenceDTO(businessUnit.Agence)
};
return collaborateurDTO;
return businessUnitDTO;
}
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 CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur)
{
CollaborateurDTO collaborateurDTO = new CollaborateurDTO()
{
Id = collaborateur.Id,
Prenom = collaborateur.Prenom,
Nom = collaborateur.Nom,
MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee
};
collaborateurDTO.Referent = new ReferentDTO()
{
Id = collaborateur.Referent.Id,
Prenom = collaborateur.Referent.Prenom,
Nom = collaborateur.Referent.Nom,
MailApside = collaborateur.Referent.MailApside
DateArrivee = collaborateur.DateArrivee,
};
collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit);
collaborateurDTO.Referent = GetReferentDTO(collaborateur.Referent);
return collaborateurDTO;
}
public List<CollaborateurDTO> GetCollaborateurs()
{
throw new NotImplementedException();
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)
@ -108,5 +126,19 @@ namespace EPAServeur.Services
{
throw new NotImplementedException();
}
public 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;
}
}
}

Loading…
Cancel
Save