@ -18,6 +18,15 @@ using IO.Swagger.Attributes;
using IO.Swagger.Security ;
using Microsoft.AspNetCore.Authorization ;
using IO.Swagger.DTO ;
using System.ComponentModel ;
using EPAServeur.IServices ;
using Microsoft.Extensions.Logging ;
using System.Threading.Tasks ;
using EPAServeur.Exceptions ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.Extensions.Hosting ;
using Microsoft.AspNetCore.Http ;
namespace IO.Swagger.Controllers
{
@ -27,6 +36,17 @@ namespace IO.Swagger.Controllers
[ApiController]
public class FormationsApiController : ControllerBase
{
private readonly IFormationService formationService ;
private readonly ILogger < FormationsApiController > logger ;
private readonly IWebHostEnvironment env ;
public FormationsApiController ( IFormationService _f ormationService , ILogger < FormationsApiController > _l ogger , IWebHostEnvironment _ env )
{
formationService = _f ormationService ;
logger = _l ogger ;
env = _ env ;
}
/// <summary>
///
/// </summary>
@ -47,29 +67,57 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 415, type: typeof(ErreurDTO), description: "L’opération ne peut pas être effectuée car certaines données sont manquantes")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult AddFormation ( [ FromBody ] FormationDTO body )
public virtual async Task < IActionResult > AddFormation ( [ FromBody ] FormationDTO body )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Ajout d'une nouvelle formation." ) ;
try
{
body = await formationService . AddFormationAsync ( body ) ;
}
catch ( FormationInvalidException e )
{
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(201, default(FormationDTO));
if ( env . IsDevelopment ( ) )
logger . LogInformation ( e . Message ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = e . Message ,
} ;
return StatusCode ( erreur . Code . Value , erreur . Message ) ;
}
catch ( DbUpdateException e )
{
logger . LogError ( e . Message ) ;
//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));
ErreurDTO erreur = new ErreurDTO
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur est survenue sur le serveur lors de l'ajout de la formation." ,
} ;
//TODO: Uncomment the next line to return response 415 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(415, default(ErreurDTO));
return StatusCode ( erreur . Code . Value , erreur ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "{\n \"heure\" : 1,\n \"participations\" : [ {\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 7,\n \"intitule\" : \"intitule\"\n }, {\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 7,\n \"intitule\" : \"intitule\"\n } ],\n \"organisme\" : \"organisme\",\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 2\n },\n \"estCertifiee\" : true,\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"intitule\" : \"intitule\",\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 1\n },\n \"jour\" : 1,\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estRealisee\" : true,\n \"id\" : 3,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"idAgence\" : 7,\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 4\n }\n}" ;
ErreurDTO erreur = new ErreurDTO
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur." ,
} ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < FormationDTO > ( exampleJson )
: default ( FormationDTO ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Nouvelle formation ajoutée." ) ;
return Created ( "" , body ) ;
}
/// <summary>
@ -91,24 +139,69 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n'a pas été trouvée")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult DeleteFormation ( [ FromRoute ] [ Required ] long? idFormation )
public virtual async Task < IActionResult > DeleteFormation ( [ FromRoute ] [ Required ] long idFormation )
{
try
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Suppresion de la formation {idFormation}." , idFormation ) ;
FormationDTO formation = await formationService . DeleteFormationByIdAsync ( idFormation ) ;
}
catch ( FormationNotFoundException e )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( e . Message ) ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status404NotFound ,
Message = e . Message
} ;
return NotFound ( erreur ) ;
}
catch ( DbUpdateConcurrencyException e )
{
logger . LogError ( e . Message ) ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = string . Format ( "La formation {0} n'a pas pu être supprimée car elle est prise par une autre ressource." , idFormation )
} ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
catch ( DbUpdateException e )
{
logger . LogError ( e . Message ) ;
ErreurDTO erreur = new ErreurDTO ( )
{
//TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(204);
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur est survenue sur le serveur lors de la suppression de la formation."
} ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
return StatusCode ( erreur . Code . Value , erreur ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//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));
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
//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));
return StatusCode ( erreur . Code . Value , erreur ) ;
}
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Formation {idFormation} supprimée avec succès." , idFormation ) ;
throw new NotImplementedException ( ) ;
return NoContent ( ) ;
}
/// <summary>
@ -131,29 +224,47 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n'a pas été trouvée")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetFormationById ( [ FromRoute ] [ Required ] long? idFormation )
public virtual async Task < IActionResult > GetFormationById ( [ FromRoute ] [ Required ] long 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)) ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération de la formation {idFormation}." , idFormation ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
FormationDTO formationDTO = null ;
//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));
try
{
formationDTO = await formationService . GetFormationByIdAsync ( idFormation ) ;
}
catch ( FormationNotFoundException e )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( e . Message ) ;
ErreurDTO erreurDTO = new ErreurDTO ( )
{
Code = StatusCodes . Status404NotFound ,
Message = e . Message
} ;
//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));
return NotFound ( erreurDTO ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "{\n \"heure\" : 1,\n \"participations\" : [ {\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 7,\n \"intitule\" : \"intitule\"\n }, {\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 7,\n \"intitule\" : \"intitule\"\n } ],\n \"organisme\" : \"organisme\",\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 2\n },\n \"estCertifiee\" : true,\n \"type\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n },\n \"intitule\" : \"intitule\",\n \"mode\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 1\n },\n \"jour\" : 1,\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"estRealisee\" : true,\n \"id\" : 3,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"idAgence\" : 7,\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 4\n }\n}" ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < FormationDTO > ( exampleJson )
: default ( FormationDTO ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Formation {idFormation} récupérée." , idFormation ) ;
return Ok ( formationDTO ) ;
}
/// <summary>
@ -182,26 +293,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accéder à la ressource n'est pas authentifié")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetFormations ( [ FromQuery ] long? idAgence , [ FromQuery ] List < int? > idStatuts , [ FromQuery ] bool? asc , [ FromQuery ] int? numPage , [ FromQuery ] [ Range ( 5 , 1 0 0 ) ] int? parPAge , [ FromQuery ] string texte , [ FromQuery ] string tri , [ FromQuery ] DateTime ? dateDebut , [ FromQuery ] DateTime ? dateFin )
public virtual async Task < IActionResult > GetFormations ( [ FromQuery ] long? idAgence , [ FromQuery ] List < int? > idStatuts , [ FromQuery ] bool? asc , [ FromQuery ] int? numPage , [ FromQuery ] [ Range ( 5 , 1 0 0 ) ] [ DefaultValue ( 1 5 ) ] int? parPAge , [ FromQuery ] string texte , [ FromQuery ] string tri , [ FromQuery ] DateTime ? dateDebut , [ FromQuery ] DateTime ? dateFin )
{
//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>)) ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération de la liste des formations." ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
IEnumerable < FormationDTO > formations = null ;
//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));
try
{
formations = await formationService . GetFormationsAsync ( idAgence , idStatuts , asc , numPage , parPAge , texte , tri , dateDebut , dateFin ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "[ {\n \"nbParticipations\" : 6,\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"organisme\" : \"organisme\",\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 2\n },\n \"estCertifiee\" : true,\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 4\n }\n}, {\n \"nbParticipations\" : 6,\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"organisme\" : \"organisme\",\n \"id\" : 0,\n \"dateFin\" : \"2000-01-23T04:56:07.000+00:00\",\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 2\n },\n \"estCertifiee\" : true,\n \"intitule\" : \"intitule\",\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 4\n }\n} ]" ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < List < FormationDetailsDTO > > ( exampleJson )
: default ( List < FormationDetailsDTO > ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Liste des formations récupérée." ) ;
return Ok ( formations ) ;
}
/// <summary>
@ -223,33 +342,42 @@ namespace IO.Swagger.Controllers
/// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpGet]
[Route("/api/formations/count")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
// [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetFormationsCount")]
[SwaggerResponse(statusCode: 200, type: typeof(long?), description: "OK")]
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accéder à la ressource n'est pas authentifié")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetFormationsCount ( [ FromQuery ] long? idAgence , [ FromQuery ] List < int? > idStatuts , [ FromQuery ] bool? asc , [ FromQuery ] int? numPage , [ FromQuery ] [ Range ( 5 , 1 0 0 ) ] int? parPAge , [ FromQuery ] string text e, [ FromQuery ] string tri , [ FromQuery ] DateTime ? dateDebut , [ FromQuery ] DateTime ? dateFin )
public virtual async Task < IActionResult > GetFormationsCount ( [ FromQuery ] long? idAgence , [ FromQuery ] List < int? > idStatuts , [ FromQuery ] int? numPage , [ FromQuery ] [ Range ( 5 , 1 0 0 ) ] [ DefaultValue ( 1 5 ) ] int? parPAg e, [ FromQuery ] string texte , [ FromQuery ] DateTime ? dateDebut , [ FromQuery ] DateTime ? dateFin )
{
//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(long?)) ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération du nombre total de formations." ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
long count = 0 ;
//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));
try
{
count = await formationService . GetFormationsCountAsync ( idAgence , idStatuts , numPage , parPAge , texte , dateDebut , dateFin ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "0" ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Nombre total de formations récupéré." ) ;
return Ok ( count ) ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < long? > ( exampleJson )
: default ( long? ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
}
/// <summary>
@ -269,26 +397,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accéder à la ressource n'est pas authentifié")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetModesFormation ( )
public virtual async Task < IActionResult > GetModesFormation ( )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération de la liste des modes de formation." ) ;
IEnumerable < ModeFormationDTO > modeFormations = null ;
try
{
modeFormations = await formationService . GetModesFormationAsync ( ) ;
}
catch ( Exception e )
{
//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>));
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
//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));
return StatusCode ( erreur . Code . Value , erreur ) ;
}
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 1\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 1\n} ]" ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Liste des modes de formation récupérée." ) ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < List < ModeFormationDTO > > ( exampleJson )
: default ( List < ModeFormationDTO > ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return Ok ( modeFormations ) ;
}
/// <summary>
@ -308,26 +444,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accéder à la ressource n'est pas authentifié")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetOriginesFormation ( )
public virtual async Task < 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>)) ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération de la liste des origines de formation." ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
IEnumerable < OrigineFormationDTO > origineFormations = null ;
//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));
try
{
origineFormations = await formationService . GetOriginesFormationAsync ( ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 2\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 2\n} ]" ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < List < OrigineFormationDTO > > ( exampleJson )
: default ( List < OrigineFormationDTO > ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Liste des origines de formation récupérée." ) ;
return Ok ( origineFormations ) ;
}
/// <summary>
@ -347,26 +491,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accéder à la ressource n'est pas authentifié")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetStatutsFormation ( )
public virtual async Task < 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>)) ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération de la liste des statuts de formation." ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
IEnumerable < StatutFormationDTO > statutFormations = null ;
//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));
try
{
statutFormations = await formationService . GetStatutsFormationAsync ( ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 4\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 4\n} ]" ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < List < StatutFormationDTO > > ( exampleJson )
: default ( List < StatutFormationDTO > ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Liste des statuts de formation récupérée." ) ;
return Ok ( statutFormations ) ;
}
/// <summary>
@ -386,26 +538,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accéder à la ressource n'est pas authentifié")]
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetTypesFormation ( )
public virtual async Task < 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>)) ;
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Récupération de la liste des types de formation." ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
IEnumerable < TypeFormationDTO > typeFormations = null ;
//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));
try
{
typeFormations = await formationService . GetTypesFormationAsync ( ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null ;
exampleJson = "[ {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n} ]" ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
var example = exampleJson ! = null
? JsonConvert . DeserializeObject < List < TypeFormationDTO > > ( exampleJson )
: default ( List < TypeFormationDTO > ) ; //TODO: Change the data returned
return new ObjectResult ( example ) ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Liste des types de formation récupérée." ) ;
return Ok ( typeFormations ) ;
}
/// <summary>
@ -430,27 +590,95 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n'a pas été trouvée")]
[SwaggerResponse(statusCode: 415, type: typeof(ErreurDTO), description: "L’opération ne peut pas être effectuée car certaines données sont manquantes")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult UpdateFormation ( [ FromBody ] FormationDTO body , [ FromRoute ] [ Required ] long? idFormation )
public virtual async Task < IActionResult > UpdateFormation ( [ FromBody ] FormationDTO body , [ FromRoute ] [ Required ] long idFormation )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Mise à jour de la formation d'id {idFormation}." , idFormation ) ;
try
{
body = await formationService . UpdateFormationAsync ( idFormation , body ) ;
}
catch ( FormationIncompatibleIdException e )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( e . Message ) ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status415UnsupportedMediaType ,
Message = e . Message ,
} ;
return StatusCode ( erreur . Code . Value , erreur . Message ) ;
}
catch ( FormationInvalidException e )
{
if ( env . IsDevelopment ( ) )
logger . LogInformation ( e . Message ) ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status415UnsupportedMediaType ,
Message = e . Message ,
} ;
return StatusCode ( erreur . Code . Value , erreur . Message ) ;
}
catch ( FormationNotFoundException e )
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200);
if ( env . IsDevelopment ( ) )
logger . LogInformation ( e . Message ) ;
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status404NotFound ,
Message = e . Message
} ;
return NotFound ( erreur ) ;
}
catch ( DbUpdateConcurrencyException e )
{
logger . LogError ( e . Message ) ;
//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));
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = string . Format ( "La formation {0} n'a pas pu être supprimée car elle est prise par une autre ressource." , idFormation )
} ;
//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));
return StatusCode ( erreur . Code . Value , erreur ) ;
}
catch ( DbUpdateException e )
{
logger . LogError ( e . Message ) ;
//TODO: Uncomment the next line to return response 415 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(415, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur est survenue sur le serveur lors de la suppression de la formation."
} ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
catch ( Exception e )
{
logger . LogError ( e . Message ) ;
ErreurDTO erreur = new ErreurDTO ( )
{
Code = StatusCodes . Status500InternalServerError ,
Message = "Une erreur inconnue est survenue sur le serveur."
} ;
return StatusCode ( erreur . Code . Value , erreur ) ;
}
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
if ( env . IsDevelopment ( ) )
logger . LogInformation ( "Update effectué avec succès" ) ;
throw new NotImplementedException ( ) ;
return Ok ( body ) ;
}
}
}