Intégration du service DemandeFormationService dans DemandeFormationApi

develop
jboinembalome 3 years ago
parent bc43b2f2ff
commit dbd3888e27
  1. 445
      EPAServeur/Controllers/DemandesFormationApi.cs

@ -19,15 +19,34 @@ using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
using EPAServeur.IServices;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting;
using System.Threading.Tasks;
using EPAServeur.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace IO.Swagger.Controllers
{
{
/// <summary>
///
/// </summary>
[ApiController]
public class DemandesFormationApiController : ControllerBase
{
{
private readonly IDemandeFormationService demandeFormationService;
private readonly ILogger<DemandesFormationApiController> logger;
private readonly IWebHostEnvironment env;
public DemandesFormationApiController(IDemandeFormationService _demandeFormationService, ILogger<DemandesFormationApiController> _logger, IWebHostEnvironment _env)
{
demandeFormationService = _demandeFormationService;
logger = _logger;
env = _env;
}
/// <summary>
///
/// </summary>
@ -40,7 +59,7 @@ namespace IO.Swagger.Controllers
/// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpPost]
[Route("/api/demandesformation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("AddDemandeFormation")]
[SwaggerResponse(statusCode: 201, type: typeof(DemandeFormationDTO), description: "Demande formation créée")]
@ -48,29 +67,58 @@ 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 AddDemandeFormation([FromBody]DemandeFormationDTO 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, default(DemandeFormationDTO));
//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));
//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 415 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(415, default(ErreurDTO));
//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 \"commentaireRefus\" : \"commentaireRefus\",\n \"libelle\" : \"libelle\",\n \"description\" : \"description\",\n \"dateDerniereReponse\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 2,\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 7\n },\n \"ep\" : {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n },\n \"formation\" : {\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 },\n \"demandeRH\" : false,\n \"dateDemande\" : \"2000-01-23T04:56:07.000+00:00\",\n \"etatDemande\" : \"EnAttente\"\n}";
var example = exampleJson != null
? JsonConvert.DeserializeObject<DemandeFormationDTO>(exampleJson)
: default(DemandeFormationDTO); //TODO: Change the data returned
return new ObjectResult(example);
public virtual async Task<IActionResult> AddDemandeFormation([FromBody] DemandeFormationDTO body)
{
if (env.IsDevelopment())
logger.LogInformation("Ajout d'une nouvelle demande de formation.");
try
{
body = await demandeFormationService.AddDemandeFormationAsync(body);
}
catch (DemandeFormationInvalidException 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 (DbUpdateException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur est survenue sur le serveur lors de l'ajout de la demande de 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);
}
if (env.IsDevelopment())
logger.LogInformation("Nouvelle demande de formation ajoutée.");
return Created("", body);
}
/// <summary>
@ -82,6 +130,7 @@ namespace IO.Swagger.Controllers
/// <response code="401">L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;est pas authentifié</response>
/// <response code="403">L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants</response>
/// <response code="404">La ressource n&#x27;a pas été trouvée</response>
/// <response code="415">L’opération ne peut pas être effectuée car certaines données sont manquantes</response>
/// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpDelete]
[Route("/api/demandesformation/{idDemandeFormation}")]
@ -91,25 +140,84 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;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: 404, type: typeof(ErreurDTO), description: "La ressource n&#x27;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 DeleteDemandeFormation([FromRoute][Required]long? idDemandeFormation)
{
//TODO: Uncomment the next line to return response 204 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(204);
public virtual async Task<IActionResult> DeleteDemandeFormation([FromRoute][Required] long idDemandeFormation)
{
try
{
if (env.IsDevelopment())
logger.LogInformation("Suppression de la demande de formation {idDemandeFormation}.", idDemandeFormation);
bool demandeFormationSupprimee = await demandeFormationService.DeleteDemandeFormationAsync(idDemandeFormation);
}
catch (DemandeFormationNotFoundException e)
{
if (env.IsDevelopment())
logger.LogInformation(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status404NotFound,
Message = e.Message
};
return NotFound(erreur);
}
catch (DemandeFormationInvalidException 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 (DbUpdateConcurrencyException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = string.Format("La demande de formation {0} n'a pas pu être supprimée car elle est prise par une autre ressource.", idDemandeFormation)
};
//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 (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 la suppression de la demande de formation."
};
//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 (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));
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur inconnue est survenue sur le serveur."
};
throw new NotImplementedException();
return StatusCode(erreur.Code.Value, erreur);
}
if (env.IsDevelopment())
logger.LogInformation("Demande de formation {idDemandeFormation} supprimée avec succès.", idDemandeFormation);
return NoContent();
}
/// <summary>
@ -138,26 +246,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;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 GetDemandesFormation([FromQuery]List<EtatDemande> etatsDemande, [FromQuery]List<long?> idBUs, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]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<DemandeFormationDTO>));
//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));
//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 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"commentaireRefus\" : \"commentaireRefus\",\n \"libelle\" : \"libelle\",\n \"description\" : \"description\",\n \"dateDerniereReponse\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 2,\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 7\n },\n \"ep\" : {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n },\n \"formation\" : {\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 },\n \"demandeRH\" : false,\n \"dateDemande\" : \"2000-01-23T04:56:07.000+00:00\",\n \"etatDemande\" : \"EnAttente\"\n}, {\n \"commentaireRefus\" : \"commentaireRefus\",\n \"libelle\" : \"libelle\",\n \"description\" : \"description\",\n \"dateDerniereReponse\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 2,\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 7\n },\n \"ep\" : {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n },\n \"formation\" : {\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 },\n \"demandeRH\" : false,\n \"dateDemande\" : \"2000-01-23T04:56:07.000+00:00\",\n \"etatDemande\" : \"EnAttente\"\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<DemandeFormationDTO>>(exampleJson)
: default(List<DemandeFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
public virtual async Task<IActionResult> GetDemandesFormation([FromQuery] List<EtatDemande> etatsDemande, [FromQuery] List<long?> idBUs, [FromQuery] bool? asc, [FromQuery] int? numPage, [FromQuery][Range(5, 100)] int? parPAge, [FromQuery] string texte, [FromQuery] string tri, [FromQuery] DateTime? dateDebut, [FromQuery] DateTime? dateFin)
{
if (env.IsDevelopment())
logger.LogInformation("Récupération de la liste des demandes de formation.");
IEnumerable<DemandeFormationDTO> demandeFormations;
try
{
demandeFormations = await demandeFormationService.GetDemandesFormationAsync(etatsDemande, idBUs, asc, numPage, parPAge, texte, tri, dateDebut, dateFin);
}
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);
}
if (env.IsDevelopment())
logger.LogInformation("Liste des demandes de formation récupérée.");
return Ok(demandeFormations);
}
/// <summary>
@ -182,26 +298,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;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 GetDemandesFormationCount([FromQuery]List<EtatDemande> etatsDemande, [FromQuery]List<long?> idBUs, [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?));
//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));
//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 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "0";
var example = exampleJson != null
? JsonConvert.DeserializeObject<long?>(exampleJson)
: default(long?); //TODO: Change the data returned
return new ObjectResult(example);
public virtual async Task<IActionResult> GetDemandesFormationCount([FromQuery] List<EtatDemande> etatsDemande, [FromQuery] List<long?> idBUs, [FromQuery] string texte, [FromQuery] DateTime? dateDebut, [FromQuery] DateTime? dateFin)
{
if (env.IsDevelopment())
logger.LogInformation("Récupération du nombre total de demandes de formation.");
long count;
try
{
count = await demandeFormationService.GetDemandesFormationCountAsync(etatsDemande, idBUs, texte, dateDebut, dateFin);
}
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);
}
if (env.IsDevelopment())
logger.LogInformation("Nombre total de demandes de formation récupéré.");
return Ok(count);
}
/// <summary>
@ -221,26 +345,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;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 GetOriginesDemandeFormation()
{
//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<OrigineDemandeFormationDTO>));
//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));
//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 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\" : 7\n}, {\n \"libelle\" : \"libelle\",\n \"id\" : 7\n} ]";
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<OrigineDemandeFormationDTO>>(exampleJson)
: default(List<OrigineDemandeFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
public virtual async Task<IActionResult> GetOriginesDemandeFormation()
{
if (env.IsDevelopment())
logger.LogInformation("Récupération de la liste des origines de demande de formation.");
IEnumerable<OrigineDemandeFormationDTO> origineDemandes;
try
{
origineDemandes = await demandeFormationService.GetOriginesDemandeFormationAsync();
}
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);
}
if (env.IsDevelopment())
logger.LogInformation("Liste des origines de demande de formation récupérée.");
return Ok(origineDemandes);
}
/// <summary>
@ -266,32 +398,95 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n&#x27;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 UpdateDemandeFormation([FromBody]DemandeFormationDTO body, [FromRoute][Required]long? idDemandeFormation)
{
//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(DemandeFormationDTO));
//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));
//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));
//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));
//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 \"commentaireRefus\" : \"commentaireRefus\",\n \"libelle\" : \"libelle\",\n \"description\" : \"description\",\n \"dateDerniereReponse\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 2,\n \"origine\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 7\n },\n \"ep\" : {\n \"obligatoire\" : true,\n \"dateDisponibilite\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 9,\n \"datePrevisionnelle\" : \"2000-01-23T04:56:07.000+00:00\"\n },\n \"formation\" : {\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 },\n \"demandeRH\" : false,\n \"dateDemande\" : \"2000-01-23T04:56:07.000+00:00\",\n \"etatDemande\" : \"EnAttente\"\n}";
var example = exampleJson != null
? JsonConvert.DeserializeObject<DemandeFormationDTO>(exampleJson)
: default(DemandeFormationDTO); //TODO: Change the data returned
return new ObjectResult(example);
public virtual async Task<IActionResult> UpdateDemandeFormation([FromBody] DemandeFormationDTO body, [FromRoute][Required] long idDemandeFormation)
{
if (env.IsDevelopment())
logger.LogInformation("Mise à jour de la demande de formation d'id {idDemandeFormation}.", idDemandeFormation);
try
{
body = await demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, body);
}
catch (DemandeFormationInvalidException 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 (DemandeFormationIncompatibleIdException 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 (DemandeFormationNotFoundException 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 demande de formation {0} n'a pas pu être mise à jour car elle est prise par une autre ressource.", idDemandeFormation)
};
return StatusCode(erreur.Code.Value, erreur);
}
catch (DbUpdateException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur est survenue sur le serveur lors de la mise à jour de la demande de 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);
}
if (env.IsDevelopment())
logger.LogInformation("Update effectué avec succès");
return Ok(body);
}
}
}

Loading…
Cancel
Save