Implémentation du service formation et de l'api formation

develop
jboinembalome 4 years ago
parent a099587a74
commit cda46536ee
  1. 276
      Controllers/FormationsApi.cs
  2. 28
      IServices/IFormationService.cs
  3. 336
      Services/FormationService.cs
  4. 2
      Startup.cs

@ -18,6 +18,7 @@ using IO.Swagger.Attributes;
using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.DTO;
using EPAServeur.IServices;
namespace IO.Swagger.Controllers
{
@ -26,7 +27,14 @@ namespace IO.Swagger.Controllers
/// </summary>
[ApiController]
public class FormationsApiController : ControllerBase
{
{
private readonly IFormationService formationService;
public FormationsApiController(IFormationService _formationService)
{
formationService = _formationService;
}
/// <summary>
///
/// </summary>
@ -36,19 +44,21 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpPost]
[Route("/api/formations")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("AjouterFormation")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult AjouterFormation([FromBody]FormationDTO body)
{
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(201);
//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));
throw new NotImplementedException();
{
switch (formationService.AddFormation(body))
{
case 0:
return StatusCode(201);
case 1:
return Forbid();
default:
return NotFound();
}
}
/// <summary>
@ -60,19 +70,37 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpDelete]
[Route("/api/formations/{idFormation}/supprimer")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("DeleteFormation")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult DeleteFormation([FromRoute][Required]decimal? idFormation)
{
//TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(204);
//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));
throw new NotImplementedException();
{
int id = 0;
try
{
id = Convert.ToInt32(idFormation);
}
catch (Exception ex)
{
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = "403",
Message = "Impossible de convertir le paramètre idFormation en int. " + ex.Message
};
return StatusCode(403, erreurDTO);
}
switch (formationService.DeleteFormationById(id))
{
case 0:
return NoContent();
case 1:
return Forbid();
default:
return NotFound();
}
}
/// <summary>
@ -90,29 +118,29 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/formations/annulees")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetFormationAnnulees")]
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetFormationAnnulees([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]int? idAgence, [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<FormationDetailsDTO>));
return StatusCode(200, formationService.GetFormationAnnulees());
//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));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n}, {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<FormationDetailsDTO>>(exampleJson)
: default(List<FormationDetailsDTO>); //TODO: Change the data returned
return new ObjectResult(example);
//string exampleJson = null;
//exampleJson = "[ {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n}, {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n} ]";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<FormationDetailsDTO>>(exampleJson)
// : default(List<FormationDetailsDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -125,29 +153,39 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/formations/{idFormation}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetFormationById")]
[SwaggerResponse(statusCode: 200, type: typeof(FormationDTO), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetFormationById([FromRoute][Required]decimal? idFormation)
{
{
//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(FormationDTO));
//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));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
string exampleJson = null;
exampleJson = "{\n \"heure\" : 1.4658129805029452,\n \"participantsFormation\" : [ {\n \"date\" : \"2000-01-23T04:56:07.000+00:00\",\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 5,\n \"formation\" : \"formation\",\n \"collaborateur\" : \"collaborateur\",\n \"statut\" : \"statut\"\n }, {\n \"date\" : \"2000-01-23T04:56:07.000+00:00\",\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 5,\n \"formation\" : \"formation\",\n \"collaborateur\" : \"collaborateur\",\n \"statut\" : \"statut\"\n } ],\n \"organisme\" : \"organisme\",\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"jour\" : 5.962133916683182,\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n }\n}";
var example = exampleJson != null
? JsonConvert.DeserializeObject<FormationDTO>(exampleJson)
: default(FormationDTO); //TODO: Change the data returned
return new ObjectResult(example);
FormationDTO formationDTO = formationService.GetFormationById(Convert.ToInt32(idFormation));
if (formationDTO == null)
{
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = "404",
Message = "Le formateur n'existe pas",
};
return NotFound(erreurDTO);
}
return Ok(formationDTO);
//string exampleJson = null;
//exampleJson = "{\n \"heure\" : 1.4658129805029452,\n \"participantsFormation\" : [ {\n \"date\" : \"2000-01-23T04:56:07.000+00:00\",\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 5,\n \"formation\" : \"formation\",\n \"collaborateur\" : \"collaborateur\",\n \"statut\" : \"statut\"\n }, {\n \"date\" : \"2000-01-23T04:56:07.000+00:00\",\n \"idCollaborateur\" : \"046b6c7f-0b8a-43b9-b35d-6489e6daee91\",\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 5,\n \"formation\" : \"formation\",\n \"collaborateur\" : \"collaborateur\",\n \"statut\" : \"statut\"\n } ],\n \"organisme\" : \"organisme\",\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"jour\" : 5.962133916683182,\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n }\n}";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<FormationDTO>(exampleJson)
// : default(FormationDTO); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -165,29 +203,29 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/formations/realisees")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetFormationRealisee")]
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n&#x27;a pas été trouvée")]
public virtual IActionResult GetFormationRealisee([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]int? idAgence, [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<FormationDetailsDTO>));
return StatusCode(200, formationService.GetFormationRealisee());
//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));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n}, {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<FormationDetailsDTO>>(exampleJson)
: default(List<FormationDetailsDTO>); //TODO: Change the data returned
return new ObjectResult(example);
//string exampleJson = null;
//exampleJson = "[ {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n}, {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n} ]";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<FormationDetailsDTO>>(exampleJson)
// : default(List<FormationDetailsDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -205,25 +243,25 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpGet]
[Route("/api/formations")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetFormations")]
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetFormations([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]int? idAgence, [FromQuery]int? statutFormation, [FromQuery]string texte, [FromQuery]string tri)
{
public virtual IActionResult GetFormations()//[FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]int? idAgence, [FromQuery]int? statutFormation, [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<FormationDetailsDTO>));
return StatusCode(200, formationService.GetFormations());
//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;
exampleJson = "[ {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n}, {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n} ]";
//string exampleJson = null;
//exampleJson = "[ {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n}, {\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estCertifie\" : true,\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n },\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"nbPartitipants\" : 1\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<FormationDetailsDTO>>(exampleJson)
: default(List<FormationDetailsDTO>); //TODO: Change the data returned
return new ObjectResult(example);
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<FormationDetailsDTO>>(exampleJson)
// : default(List<FormationDetailsDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -234,25 +272,25 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpGet]
[Route("/api/modesFormation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetModesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<ModeFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetModesFormation()
{
{
//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<ModeFormationDTO>));
return StatusCode(200, formationService.GetModesFormation());
//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;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<ModeFormationDTO>>(exampleJson)
: default(List<ModeFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
//string exampleJson = null;
//exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n} ]";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<ModeFormationDTO>>(exampleJson)
// : default(List<ModeFormationDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -263,25 +301,25 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpGet]
[Route("/api/originesFormation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetOriginesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<OrigineFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetOriginesFormation()
{
{
//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<OrigineFormationDTO>));
return StatusCode(200, formationService.GetOriginesFormation());
//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;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<OrigineFormationDTO>>(exampleJson)
: default(List<OrigineFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
//string exampleJson = null;
//exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n} ]";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<OrigineFormationDTO>>(exampleJson)
// : default(List<OrigineFormationDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -299,7 +337,7 @@ namespace IO.Swagger.Controllers
/// <response code="404">Ressource n&#x27;a pas été trouvée</response>
[HttpGet]
[Route("/api/formations/prochaines")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetProchainesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<FormationDetailsDTO>), description: "OK")]
@ -332,25 +370,25 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpGet]
[Route("/api/statutsFormation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetStatutsFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<StatutFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetStatutsFormation()
{
{
//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<StatutFormationDTO>));
return StatusCode(200, formationService.GetStatutsFormation());
//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;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<StatutFormationDTO>>(exampleJson)
: default(List<StatutFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
//string exampleJson = null;
//exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n} ]";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<StatutFormationDTO>>(exampleJson)
// : default(List<StatutFormationDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -361,25 +399,25 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpGet]
[Route("/api/typesFormation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetTypesFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(List<TypeFormationDTO>), description: "OK")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult GetTypesFormation()
{
{
//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<TypeFormationDTO>));
return StatusCode(200, formationService.GetTypesFormation());
//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;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<TypeFormationDTO>>(exampleJson)
: default(List<TypeFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
//string exampleJson = null;
//exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 5\n} ]";
// var example = exampleJson != null
// ? JsonConvert.DeserializeObject<List<TypeFormationDTO>>(exampleJson)
// : default(List<TypeFormationDTO>); //TODO: Change the data returned
//return new ObjectResult(example);
}
/// <summary>
@ -393,12 +431,12 @@ namespace IO.Swagger.Controllers
/// <response code="403">Acces interdit</response>
[HttpPut]
[Route("/api/formations/{idFormation}/update")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("UpdateFormation")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")]
public virtual IActionResult UpdateFormation([FromBody]FormationDTO body, [FromRoute][Required]decimal? idFormation)
{
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200);
@ -407,8 +445,38 @@ namespace IO.Swagger.Controllers
//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));
int id = 0;
try
{
id = Convert.ToInt32(idFormation);
}
catch (Exception ex)
{
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = "403",
Message = "Impossible de convertir le paramètre idFormation en int. " + ex.Message
};
return StatusCode(403, erreurDTO);
}
switch (formationService.DeleteFormationById(id))
{
case 0:
return StatusCode(201);
case 1:
return StatusCode(200);
case 2:
return StatusCode(403);
default:
return NotFound();
}
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
formationService.UpdateFormation(body);
return StatusCode(201);
throw new NotImplementedException();
}
}
}

@ -0,0 +1,28 @@
using EPAServeur.Context;
using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.IServices
{
public interface IFormationService
{
FormationDTO GetFormationById(int? id);
IEnumerable<FormationDTO> GetFormations();
IEnumerable<FormationDTO> GetFormationAnnulees();
IEnumerable<FormationDTO> GetFormationRealisee();
IEnumerable<FormationDTO> GetProchainesFormation();
IEnumerable<ModeFormationDTO> GetModesFormation();
IEnumerable<OrigineFormationDTO> GetOriginesFormation();
IEnumerable<StatutFormationDTO> GetStatutsFormation();
IEnumerable<TypeFormationDTO> GetTypesFormation();
byte AddFormation(FormationDTO formationDTO);
byte UpdateFormation(FormationDTO formationDTO);
byte DeleteFormationById(int? id);
}
}

@ -0,0 +1,336 @@
using EPAServeur.Context;
using EPAServeur.IServices;
using EPAServeur.Models.Formation;
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 FormationService : IFormationService
{
private readonly EpContext epContext;
public FormationService(EpContext _epContext)
{
epContext = _epContext;
}
public FormationDTO GetFormationById(int? id)
{
Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == id);
if (formation == null)
return null;
return GetFormationDTO(formation);
}
public IEnumerable<FormationDTO> GetFormations()
{
IEnumerable<Formation> formations = epContext.Formation;
IEnumerable<FormationDTO> formationDTOs = formations.Select(formation => GetFormationDTO(formation));
return formationDTOs;
}
public IEnumerable<FormationDTO> GetFormationAnnulees()
{
IEnumerable<Formation> formations = epContext.Formation;
IEnumerable<FormationDTO> formationDTOs = formations.Where(formation => formation.Statut.Id == 4).Select(formation => GetFormationDTO(formation));
return formationDTOs;
}
public IEnumerable<FormationDTO> GetFormationRealisee()
{
IEnumerable<Formation> formations = epContext.Formation;
IEnumerable<FormationDTO> formationDTOs = formations.Where(formation => formation.Statut.Id == 3).Select(formation => GetFormationDTO(formation));
return formationDTOs;
}
public IEnumerable<FormationDTO> GetProchainesFormation()
{
IEnumerable<Formation> formations = epContext.Formation;
IEnumerable<FormationDTO> formationDTOs = formations.Where(formation => formation.Statut.Id == 1 && formation.Statut.Id == 2).Select(formation => GetFormationDTO(formation)).OrderBy(formation => formation.DateDebut);
return formationDTOs;
}
public IEnumerable<ModeFormationDTO> GetModesFormation()
{
IEnumerable<ModeFormation> modeFormations = epContext.ModeFormation;
IEnumerable<ModeFormationDTO> modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation));
return modeFormationDTOs;
}
public IEnumerable<OrigineFormationDTO> GetOriginesFormation()
{
IEnumerable<OrigineFormation> origineFormations = epContext.OrigineFormation;
IEnumerable<OrigineFormationDTO> origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation));
return origineFormationDTOs;
}
public IEnumerable<StatutFormationDTO> GetStatutsFormation()
{
IEnumerable<StatutFormation> statutFormations = epContext.StatutFormation;
IEnumerable<StatutFormationDTO> statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation));
return statutFormationDTOs;
}
public IEnumerable<TypeFormationDTO> GetTypesFormation()
{
IEnumerable<TypeFormation> typeFormations = epContext.TypeFormation;
IEnumerable<TypeFormationDTO> typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation));
return typeFormationDTOs;
}
public byte AddFormation(FormationDTO formationDTO)
{
Formation formation = new Formation();
formation = SetFormation(formation, formationDTO);
if (formation.Statut != null)
{
epContext.StatutFormation.Attach(formation.Statut);
}
epContext.OrigineFormation.Attach(formation.Origine);
epContext.ModeFormation.Attach(formation.ModeFormation);
epContext.TypeFormation.Attach(formation.TypeFormation);
epContext.Add(formation);
try
{
epContext.SaveChanges();
}
catch (Exception)
{
return 1;
}
return 0;
}
public byte UpdateFormation(FormationDTO formationDTO)
{
Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == formationDTO.Id);
if (formation == null)
return 1;
formation = SetFormation(formation, formationDTO);
try
{
epContext.SaveChanges();
}
catch (Exception)
{
return 2;
}
return 0;
}
public byte DeleteFormationById(int? id)
{
Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == id);
if (formation == null)
return 1;
try
{
epContext.Remove(formation);
epContext.SaveChanges();
}
catch (Exception)
{
return 2;
}
return 0;
}
#region Object to DTO
private FormationDTO GetFormationDTO(Formation formation)
{
FormationDTO formationDTO = new FormationDTO()
{
Id = formation.Id,
Intitule = formation.Intitule,
IdAgence = formation.IdAgence,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Heure = formation.Heure,
Jour = formation.Jour,
Organisme = formation.Organisme,
EstCertifie = formation.EstCertifiee,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
Mode = GetModeFormationDTO(formation.ModeFormation),
Type = GetTypeFormationDTO(formation.TypeFormation)
};
//List<ParticipationFormationDTO> participationFormationDTOs = epContext.ParticipationFormation.Where(participationFormation => participationFormation.Formation.Id == formation.Id)
// .Select(participationFormation => new ParticipationFormationDTO()
// {
// Id = participationFormation.Id,
// DateCreation = participationFormation.DateCreation,
// Formation = participationFormation.Formation.Intitule,
// Date = participationFormation.Formation.DateDebut,
// Statut = participationFormation.Formation.Statut.Libelle,
// EstEvaluee = participationFormation.EstEvaluee,
// }).ToList();
//formationDTO.ParticipantsFormation = participationFormationDTOs;
return formationDTO;
}
private OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation)
{
if (origineFormation == null)
return null;
OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO()
{
Id = origineFormation.Id,
Libelle = origineFormation.Libelle
};
return origineFormationDTO;
}
private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
{
if (statutFormation == null)
return null;
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
{
Id = statutFormation.Id,
Libelle = statutFormation.Libelle
};
return statutFormationDTO;
}
private ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation)
{
if (modeFormation == null)
return null;
ModeFormationDTO modeFormationDTO = new ModeFormationDTO()
{
Id = modeFormation.Id,
Libelle = modeFormation.Libelle
};
return modeFormationDTO;
}
private TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation)
{
if (typeFormation == null)
return null;
TypeFormationDTO typeFormationDTO = new TypeFormationDTO()
{
Id = typeFormation.Id,
Libelle = typeFormation.Libelle
};
return typeFormationDTO;
}
#endregion
#region DTO to Object
private Formation SetFormation(Formation formation, FormationDTO formationDTO)
{
formation.Intitule = formationDTO.Intitule;
formation.IdAgence = formationDTO.IdAgence.Value;
formation.DateDebut = formationDTO.DateDebut.Value;
formation.DateFin = formationDTO.DateFin.Value;
formation.Heure = Convert.ToInt32(formationDTO.Heure.Value);
formation.Jour = Convert.ToInt32(formationDTO.Jour.Value);
formation.Organisme = formationDTO.Organisme;
formation.EstCertifiee = formationDTO.EstCertifie.Value;
formation.Origine = GetOrigineFormation(formationDTO.Origine);
formation.Statut = GetStatutFormation(formationDTO.Statut);
formation.ModeFormation = GetModeFormation(formationDTO.Mode);
formation.TypeFormation = GetTypeFormation(formationDTO.Type);
//List<ParticipationFormationDTO> participationFormationDTOs = epContext.ParticipationFormation.Where(participationFormation => participationFormation.Formation.Id == formation.Id)
// .Select(participationFormation => new ParticipationFormationDTO()
// {
// Id = participationFormation.Id,
// DateCreation = participationFormation.DateCreation,
// Formation = participationFormation.Formation.Intitule,
// Date = participationFormation.Formation.DateDebut,
// Statut = participationFormation.Formation.Statut.Libelle,
// EstEvaluee = participationFormation.EstEvaluee,
// }).ToList();
//formationDTO.ParticipantsFormation = participationFormationDTOs;
return formation;
}
private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO)
{
if (origineFormationDTO == null)
return null;
OrigineFormation origineFormation = new OrigineFormation()
{
Id = origineFormationDTO.Id.Value,
Libelle = origineFormationDTO.Libelle
};
return origineFormation;
}
private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO)
{
if (statutFormationDTO == null)
return null;
StatutFormation statutFormation = new StatutFormation()
{
Id = statutFormationDTO.Id.Value,
Libelle = statutFormationDTO.Libelle
};
return statutFormation;
}
private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO)
{
if (modeFormationDTO == null)
return null;
ModeFormation modeFormation = new ModeFormation()
{
Id = modeFormationDTO.Id.Value,
Libelle = modeFormationDTO.Libelle
};
return modeFormation;
}
private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO)
{
if (typeFormationDTO == null)
return null;
TypeFormation typeFormation = new TypeFormation()
{
Id = typeFormationDTO.Id.Value,
Libelle = typeFormationDTO.Libelle
};
return typeFormation;
}
#endregion
}
}

@ -53,7 +53,7 @@ namespace EPAServeur
//Services
services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IFormationService, FormationService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Loading…
Cancel
Save