diff --git a/Controllers/FormationsApi.cs b/Controllers/FormationsApi.cs index 4b023bf..ba84147 100644 --- a/Controllers/FormationsApi.cs +++ b/Controllers/FormationsApi.cs @@ -4,7 +4,7 @@ * API qui sra utilisée afin de faire communiquer le client et le serveur ainsi que le serveur et la boîte noire. * * OpenAPI spec version: 1.3.4 - * + * * Generated by: https://github.com/swagger-api/swagger-codegen.git */ using System; @@ -18,17 +18,27 @@ using IO.Swagger.Attributes; using IO.Swagger.Security; using Microsoft.AspNetCore.Authorization; using IO.Swagger.DTO; +using EPAServeur.IServices; +using System.Reflection.Metadata.Ecma335; +using System.Runtime.InteropServices.WindowsRuntime; namespace IO.Swagger.Controllers -{ +{ /// - /// + /// /// [ApiController] public class FormationsApiController : ControllerBase - { + { + private readonly IFormationService formationService; + + public FormationsApiController(IFormationService _formationService) + { + formationService = _formationService; + } + /// - /// + /// /// /// Ajouter une nouvelle formation /// @@ -36,23 +46,27 @@ namespace IO.Swagger.Controllers /// Acces interdit [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(); + public virtual IActionResult AjouterFormation([FromBody] FormationDTO body) + { + FormationDTO nouvelleFormation = formationService.AddFormation(body); + + return Created("", nouvelleFormation); + //if (body.Id != null && body.Id > 0) + //{ + // return StatusCode(201, body); + //} + //else + //{ + // return NotFound(); + //} } /// - /// + /// /// /// Supprimer une formation /// id formation @@ -60,23 +74,26 @@ namespace IO.Swagger.Controllers /// Acces interdit [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]long? 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(); + public virtual IActionResult DeleteFormation([FromRoute][Required] long? idFormation) + { + if (!formationService.DeleteFormationById(idFormation)) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucune formation trouvée" + }; + return NotFound(erreur); + } + return NoContent(); } /// - /// + /// /// /// Récupérer les formations annulées /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) @@ -90,33 +107,31 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/formations/annulees")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetFormationAnnulees")] [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] - public virtual IActionResult GetFormationAnnulees([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]long? idAgence, [FromQuery]string texte, [FromQuery]string tri) - { + 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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable formations = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); + if (formations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucune formation annulée" + }; + return NotFound(erreur); + } + + return Ok(formations); } /// - /// + /// /// /// Récupérer une formation par son id /// id formation @@ -125,33 +140,29 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [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'a pas été trouvée")] - public virtual 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)); - - //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\" : 5,\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\" : 2,\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\" : 2,\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,\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 \"idAgence\" : 1,\n \"statut\" : {\n \"libelle\" : \"libelle\",\n \"id\" : 6\n }\n}"; - - var example = exampleJson != null - ? JsonConvert.DeserializeObject(exampleJson) - : default(FormationDTO); //TODO: Change the data returned - return new ObjectResult(example); + public virtual IActionResult GetFormationById([FromRoute][Required] long? idFormation) + { + FormationDTO formationDTO = formationService.GetFormationById(Convert.ToInt32(idFormation)); + if (formationDTO == null) + { + ErreurDTO erreurDTO = new ErreurDTO() + { + Code = "404", + Message = "La formation n'existe pas", + }; + return NotFound(erreurDTO); + } + return Ok(formationDTO); } /// - /// + /// /// /// Récupérer les formations réalisées /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) @@ -165,33 +176,32 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/formations/realisees")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetFormationRealisee")] [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] - public virtual IActionResult GetFormationRealisee([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]long? idAgence, [FromQuery]string texte, [FromQuery]string tri) - { + 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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable formations = formationService.GetFormationRealisee(asc, numPage, parPAge, idAgence, texte, tri); + if (formations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucune formation réalisée" + }; + return NotFound(erreur); + } + + return Ok(formations); } + /// - /// + /// /// /// Récupérer la liste des formations /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) @@ -205,87 +215,90 @@ namespace IO.Swagger.Controllers /// Acces interdit [HttpGet] [Route("/api/formations")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetFormations")] [SwaggerResponse(statusCode: 200, type: typeof(List), 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]long? 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)); - - //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} ]"; - - var example = exampleJson != null - ? JsonConvert.DeserializeObject>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable formations = formationService.GetFormations(asc, numPage, parPAge, idAgence, texte, tri); + if (formations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucune formation" + }; + return NotFound(erreur); + } + + return Ok(formations); } /// - /// + /// /// /// Récupérer les modes de formation /// OK /// Acces interdit [HttpGet] [Route("/api/modesFormation")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetModesFormation")] [SwaggerResponse(statusCode: 200, type: typeof(List), 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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable modeFormations = formationService.GetModesFormation(); + if (modeFormations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucun mode de formation" + }; + return NotFound(erreur); + } + + return Ok(modeFormations); } /// - /// + /// /// /// Récupérer les origines de formation /// OK /// Acces interdit [HttpGet] [Route("/api/originesFormation")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetOriginesFormation")] [SwaggerResponse(statusCode: 200, type: typeof(List), 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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable origineFormations = formationService.GetOriginesFormation(); + if (origineFormations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucune origine de formation" + }; + return NotFound(erreur); + } + + return Ok(origineFormations); } /// - /// + /// /// /// Récupérer les formations plannifié et replannifié /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) @@ -299,91 +312,91 @@ namespace IO.Swagger.Controllers /// Ressource n'a pas été trouvée [HttpGet] [Route("/api/formations/prochaines")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetProchainesFormation")] [SwaggerResponse(statusCode: 200, type: typeof(List), description: "OK")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] [SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "Ressource n'a pas été trouvée")] - public virtual IActionResult GetProchainesFormation([FromQuery][Required()]bool? asc, [FromQuery][Required()]int? numPage, [FromQuery][Required()]int? parPAge, [FromQuery]long? idAgence, [FromQuery]string texte, [FromQuery]string tri) - { + public virtual IActionResult GetProchainesFormation([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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable formations = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); + if (formations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucune prochaine formation" + }; + return NotFound(erreur); + } + + return Ok(formations); } /// - /// + /// /// /// Récupérer les statuts de formation /// OK /// Acces interdit [HttpGet] [Route("/api/statutsFormation")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetStatutsFormation")] [SwaggerResponse(statusCode: 200, type: typeof(List), 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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable statutFormations = formationService.GetStatutsFormation(); + if (statutFormations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucun statut de formation" + }; + return NotFound(erreur); + } + + return Ok(statutFormations); } /// - /// + /// /// /// Récupérer les types de formation /// OK /// Acces interdit [HttpGet] [Route("/api/typesFormation")] - [Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] + //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] [ValidateModelState] [SwaggerOperation("GetTypesFormation")] [SwaggerResponse(statusCode: 200, type: typeof(List), 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)); - - //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>(exampleJson) - : default(List); //TODO: Change the data returned - return new ObjectResult(example); + IEnumerable typeFormations = formationService.GetTypesFormation(); + if (typeFormations == null) + { + ErreurDTO erreur = new ErreurDTO() + { + Code = "404", + Message = "Aucun type de formation" + }; + return NotFound(erreur); + } + + return Ok(typeFormations); } /// - /// + /// /// /// Mettre à jour une formation /// @@ -393,22 +406,33 @@ namespace IO.Swagger.Controllers /// Acces interdit [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]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); - - //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)); + public virtual IActionResult UpdateFormation([FromBody] FormationDTO body, [FromRoute][Required] long? idFormation) + { + FormationDTO formation = formationService.UpdateFormation(body); + if (formation == null) + { + formation = formationService.AddFormation(body); + return Created("", formation); + } + return Ok(formation); + + + //switch (formationService.UpdateFormation(body)) + //{ + // case 0: + // return Ok(); + // case 1: + // return StatusCode(201); + // case 2: + // return Forbid(); + // default: + // return NotFound(); + //} - throw new NotImplementedException(); } } } diff --git a/IServices/IFormationService.cs b/IServices/IFormationService.cs new file mode 100644 index 0000000..dbe8278 --- /dev/null +++ b/IServices/IFormationService.cs @@ -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(long? id); + + IEnumerable GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); + IEnumerable GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); + IEnumerable GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); + IEnumerable GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); + IEnumerable GetModesFormation(); + IEnumerable GetOriginesFormation(); + IEnumerable GetStatutsFormation(); + IEnumerable GetTypesFormation(); + + FormationDTO AddFormation(FormationDTO formationDTO); + FormationDTO UpdateFormation(FormationDTO formationDTO); + bool DeleteFormationById(long? id); + } +} diff --git a/Models/Formation/Formation.cs b/Models/Formation/Formation.cs index 6f56f51..b533ce9 100644 --- a/Models/Formation/Formation.cs +++ b/Models/Formation/Formation.cs @@ -12,8 +12,8 @@ namespace EPAServeur.Models.Formation public long IdAgence { get; set; } public DateTime DateDebut { get; set; } public DateTime DateFin { get; set; } - public long Jour { get; set; } - public long Heure { get; set; } + public int Jour { get; set; } + public int Heure { get; set; } public string Organisme { get; set; } public bool EstCertifiee { get; set; } public StatutFormation Statut { get; set; } diff --git a/Models/Formation/ModeFormation.cs b/Models/Formation/ModeFormation.cs index 3e3a86a..8b05493 100644 --- a/Models/Formation/ModeFormation.cs +++ b/Models/Formation/ModeFormation.cs @@ -7,7 +7,7 @@ namespace EPAServeur.Models.Formation { public class ModeFormation { - public long Id { get; set; } + public int Id { get; set; } public string Libelle { get; set; } public List Formations { get; set; } } diff --git a/Models/Formation/OrigineDemandeFormation.cs b/Models/Formation/OrigineDemandeFormation.cs index 801cb2e..e3fc102 100644 --- a/Models/Formation/OrigineDemandeFormation.cs +++ b/Models/Formation/OrigineDemandeFormation.cs @@ -7,7 +7,7 @@ namespace EPAServeur.Models.Formation { public class OrigineDemandeFormation { - public long Id { get; set; } + public int Id { get; set; } public string Libelle { get; set; } public List DemandeFormations { get; set; } } diff --git a/Models/Formation/OrigineFormation.cs b/Models/Formation/OrigineFormation.cs index 85b3373..07b87b8 100644 --- a/Models/Formation/OrigineFormation.cs +++ b/Models/Formation/OrigineFormation.cs @@ -7,7 +7,7 @@ namespace EPAServeur.Models.Formation { public class OrigineFormation { - public long Id { get; set; } + public int Id { get; set; } public string Libelle { get; set; } public List Formations { get; set; } } diff --git a/Models/Formation/StatutFormation.cs b/Models/Formation/StatutFormation.cs index c871947..baf377a 100644 --- a/Models/Formation/StatutFormation.cs +++ b/Models/Formation/StatutFormation.cs @@ -7,7 +7,7 @@ namespace EPAServeur.Models.Formation { public class StatutFormation { - public long Id { get; set; } + public int Id { get; set; } public string Libelle { get; set; } public List Formations { get; set; } } diff --git a/Models/Formation/Theme.cs b/Models/Formation/Theme.cs index e6e1955..27a60fe 100644 --- a/Models/Formation/Theme.cs +++ b/Models/Formation/Theme.cs @@ -7,7 +7,7 @@ namespace EPAServeur.Models.Formation { public class Theme { - public long Id { get; set; } + public int Id { get; set; } public string Libelle { get; set; } } } diff --git a/Models/Formation/TypeFormation.cs b/Models/Formation/TypeFormation.cs index 42ded9b..0164ee3 100644 --- a/Models/Formation/TypeFormation.cs +++ b/Models/Formation/TypeFormation.cs @@ -7,7 +7,7 @@ namespace EPAServeur.Models.Formation { public class TypeFormation { - public long Id { get; set; } + public int Id { get; set; } public string Libelle { get; set; } public List Formations { get; set; } } diff --git a/Services/FormationService.cs b/Services/FormationService.cs new file mode 100644 index 0000000..775bf3d --- /dev/null +++ b/Services/FormationService.cs @@ -0,0 +1,655 @@ +using EPAServeur.Context; +using EPAServeur.IServices; +using EPAServeur.Models.Formation; +using IO.Swagger.DTO; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace EPAServeur.Services +{ + public class FormationService : IFormationService + { + #region Variables + + private readonly EpContext epContext; + + #endregion + + #region Contructeurs + + /// + /// Constructeur de la classe FormationService + /// + /// + public FormationService(EpContext _epContext) + { + epContext = _epContext; + } + + #endregion + + #region Méthodes Service + + /// + /// Récupérer une formation par son id + /// + /// + /// + public FormationDTO GetFormationById(long? id) + { + Formation formation = epContext.Formation.Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation) + .FirstOrDefault(formation => formation.Id == id); + + if (formation == null) + return null; + + return GetFormationDTO(formation); + } + + /// + /// Récupérer la liste des formations + /// + /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) + /// Numéro de la page du tableau qui affiche les données + /// Nombre d'éléments affiché sur chaque page du tableau + /// id de l'agence à laquelle sont rattachées les données à récupérer + /// Texte permettant d'identifier l'objet rechercher + /// Colonne du tableau sur lequel le tri s'effectue + /// + public IEnumerable GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) + { + IEnumerable formations; + IEnumerable formationDTOs; + + if (texte == null) + texte = ""; + else + texte = texte.ToLower(); + + int skip = (numPage.Value - 1) * parPAge.Value; + int take = parPAge.Value; + + if (idAgence != null) + { + try + { + formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + } + catch (Exception ex) + { + throw; + } + } + else + { + try + { + formations = epContext.Formation.Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + } + catch (Exception ex) + { + throw; + } + } + + + if (formations == null) + return new List(); + + formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); + + return formationDTOs; + } + + /// + /// Récupérer les formations annulées + /// + /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) + /// Numéro de la page du tableau qui affiche les données + /// Nombre d'éléments affiché sur chaque page du tableau + /// id de l'agence à laquelle sont rattachées les données à récupérer + /// Texte permettant d'identifier l'objet rechercher + /// Colonne du tableau sur lequel le tri s'effectue + /// + public IEnumerable GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) + { + IEnumerable formations; + IEnumerable formationDTOs; + + if (texte == null) + texte = ""; + else + texte = texte.ToLower(); + + int skip = (numPage.Value - 1) * parPAge.Value; + int take = parPAge.Value; + + if (idAgence != null) + formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.Id == 4) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + else + formations = epContext.Formation.Where(formation => formation.Statut.Id == 4) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + + if (formations == null) + return new List(); + + formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); + + return formationDTOs; + } + + /// + /// Récupérer les formations réalisées + /// + /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) + /// Numéro de la page du tableau qui affiche les données + /// Nombre d'éléments affiché sur chaque page du tableau + /// id de l'agence à laquelle sont rattachées les données à récupérer + /// Texte permettant d'identifier l'objet rechercher + /// Colonne du tableau sur lequel le tri s'effectue + /// + public IEnumerable GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) + { + IEnumerable formations; + IEnumerable formationDTOs; + + if (texte == null) + texte = ""; + else + texte = texte.ToLower(); + + int skip = (numPage.Value - 1) * parPAge.Value; + int take = parPAge.Value; + + if (idAgence != null) + { + try + { + formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && formation.Statut.Id == 3) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + } + catch (Exception ex) + { + throw; + } + } + + else + { + try + { + formations = epContext.Formation.Where(formation => formation.Statut.Id == 3) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + } + catch (Exception ex) + { + throw; + } + } + + + if (formations == null) + return new List(); + + formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); + + return formationDTOs; + } + + /// + /// Récupérer les formations plannifiées et replannifiées + /// + /// Préciser si les données sont dans l'ordre (true) ou dans l'ordre inverse (false) + /// Numéro de la page du tableau qui affiche les données + /// Nombre d'éléments affiché sur chaque page du tableau + /// id de l'agence à laquelle sont rattachées les données à récupérer + /// Texte permettant d'identifier l'objet rechercher + /// Colonne du tableau sur lequel le tri s'effectue + /// + public IEnumerable GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) + { + IEnumerable formations; + IEnumerable formationDTOs; + + if (texte == null) + texte = ""; + else + texte = texte.ToLower(); + + int skip = (numPage.Value - 1) * parPAge.Value; + int take = parPAge.Value; + + if (idAgence != null) + try + { + formations = epContext.Formation.Where(formation => formation.IdAgence == idAgence && (formation.Statut.Id == 1 || formation.Statut.Id == 2)) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + } + catch (Exception ex) + { + throw; + } + + else + { + formations = epContext.Formation.Where(formation => (formation.Statut.Id == 1 || formation.Statut.Id == 2)) + .Include(formation => formation.Statut) + .Include(formation => formation.ModeFormation) + .Include(formation => formation.Origine) + .Include(formation => formation.TypeFormation); + } + + if (formations == null) + return new List(); + + formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); + + return formationDTOs; + } + + /// + /// Récupérer les modes de formation + /// + /// + public IEnumerable GetModesFormation() + { + IEnumerable modeFormations; + IEnumerable modeFormationDTOs; + try + { + modeFormations = epContext.ModeFormation; + } + catch (Exception ex) + { + throw; + } + + modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); + + return modeFormationDTOs; + } + + /// + /// Récupérer les origines de formation + /// + /// + public IEnumerable GetOriginesFormation() + { + IEnumerable origineFormations; + IEnumerable origineFormationDTOs; + + try + { + origineFormations = epContext.OrigineFormation; + } + catch (Exception ex) + { + throw; + } + + origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); + + return origineFormationDTOs; + } + + /// + /// Récupérer les statuts de formation + /// + /// + public IEnumerable GetStatutsFormation() + { + IEnumerable statutFormations; + IEnumerable statutFormationDTOs; + + try + { + statutFormations = epContext.StatutFormation; + } + catch (Exception ex) + { + + throw; + } + + statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); + + return statutFormationDTOs; + } + + /// + /// Récupérer les types de formation + /// + /// + public IEnumerable GetTypesFormation() + { + IEnumerable typeFormations; + IEnumerable typeFormationDTOs; + + try + { + typeFormations = epContext.TypeFormation; + } + catch (Exception ex) + { + throw; + } + + typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); + + return typeFormationDTOs; + } + + /// + /// Ajouter une formation + /// + /// + /// + public FormationDTO 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 ex) + { + throw; + } + + return GetFormationDTO(formation); + } + + /// + /// Modifier une formation + /// + /// + /// + public FormationDTO UpdateFormation(FormationDTO formationDTO) + { + Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == formationDTO.Id); + + if (formation == null) + { + return null; + } + + formation = SetFormation(formation, formationDTO); + try + { + epContext.SaveChanges(); + } + catch (Exception ex) + { + throw; + } + + return GetFormationDTO(formation); + } + + /// + /// Supprimer une formation + /// + /// + /// + public bool DeleteFormationById(long? id) + { + Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == id); + + if (formation == null) + return false; + + epContext.Remove(formation); + + try + { + epContext.SaveChanges(); + } + catch (Exception) + { + throw; + } + + return true; + } + + #endregion + + #region Méthodes Privée + + #region Object to DTO + /// + /// Récupère un objet FormationDTO en fonction d'un objet Formation + /// + /// + /// + 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) + }; + + return formationDTO; + } + + /// + /// Récupère un objet OrigineFormationDTO en fonction d'un objet OrigineFormation + /// + /// + /// + private OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation) + { + if (origineFormation == null) + return null; + OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO() + { + Id = origineFormation.Id, + Libelle = origineFormation.Libelle + }; + return origineFormationDTO; + } + + /// + /// Récupère un objet StatutFormationDTO en fonction d'un objet StatutFormation + /// + /// + /// + private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation) + { + if (statutFormation == null) + return null; + StatutFormationDTO statutFormationDTO = new StatutFormationDTO() + { + Id = statutFormation.Id, + Libelle = statutFormation.Libelle + }; + return statutFormationDTO; + } + + /// + /// Récupère un objet ModeFormationDTO en fonction d'un objet ModeFormation + /// + /// + /// + private ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation) + { + if (modeFormation == null) + return null; + ModeFormationDTO modeFormationDTO = new ModeFormationDTO() + { + Id = modeFormation.Id, + Libelle = modeFormation.Libelle + }; + return modeFormationDTO; + } + /// + /// Récupère un objet TypeFormationDTO en fonction d'un objet TypeFormation + /// + /// + /// + 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 + + /// + /// Modifie un objet Formation en fonction d'un objet FormationDTO + /// + /// + /// + /// + 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); + + return formation; + } + + /// + /// Récupère un objet OrigineFormation en fonction d'un objet OrigineFormationDTO + /// + /// + /// + private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO) + { + if (origineFormationDTO == null) + return null; + OrigineFormation origineFormation = new OrigineFormation() + { + Id = origineFormationDTO.Id.Value, + Libelle = origineFormationDTO.Libelle + }; + return origineFormation; + } + + /// + /// Récupère un objet StatutFormation en fonction d'un objet StatutFormationDTO + /// + /// + /// + private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO) + { + if (statutFormationDTO == null) + return null; + StatutFormation statutFormation = new StatutFormation() + { + Id = statutFormationDTO.Id.Value, + Libelle = statutFormationDTO.Libelle + }; + return statutFormation; + } + + /// + /// Récupère un objet ModeFormation en fonction d'un objet ModeFormationDTO + /// + /// + /// + private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO) + { + if (modeFormationDTO == null) + return null; + ModeFormation modeFormation = new ModeFormation() + { + Id = modeFormationDTO.Id.Value, + Libelle = modeFormationDTO.Libelle + }; + return modeFormation; + } + + /// + /// Récupère un objet TypeFormation en fonction d'un objet TypeFormationDTO + /// + /// + /// + private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO) + { + if (typeFormationDTO == null) + return null; + TypeFormation typeFormation = new TypeFormation() + { + Id = typeFormationDTO.Id.Value, + Libelle = typeFormationDTO.Libelle + }; + return typeFormation; + } + + #endregion + + #endregion + + } +} diff --git a/Startup.cs b/Startup.cs index 22e7f23..7290f43 100644 --- a/Startup.cs +++ b/Startup.cs @@ -34,7 +34,7 @@ namespace EPAServeur services.AddControllers(); services.AddAuthentication(BearerAuthenticationHandler.SchemeName) .AddScheme(BearerAuthenticationHandler.SchemeName, null); - + services.AddDbContext(); using(var context = new EpContext()) { @@ -45,7 +45,7 @@ namespace EPAServeur context.AjoutChamps(); context.AjouterNotes(); } - //faire using, check si kekchoz exkist puis appeler les méthodes de création si il n'y a rien + //faire using, check si kekchoz exkist puis appeler les m�thodes de cr�ation si il n'y a rien //API Collaborateurs services.AddScoped(); @@ -56,6 +56,7 @@ namespace EPAServeur //Services services.AddScoped(); + services.AddScoped(); services.AddScoped(); }