From 52977a45204c6abfa25aad103e5332bebf0479f4 Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Fri, 11 Sep 2020 16:34:02 +0200 Subject: [PATCH] Modification des noms de variables dans le service formation et l'api formation --- Controllers/FormationsApi.cs | 18 ++++++++--------- IServices/IFormationService.cs | 6 +++--- Services/FormationService.cs | 36 ++++++++++++++++++++++------------ 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Controllers/FormationsApi.cs b/Controllers/FormationsApi.cs index 9cfa4f1..812c683 100644 --- a/Controllers/FormationsApi.cs +++ b/Controllers/FormationsApi.cs @@ -106,7 +106,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable formations = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); - if (formations.Count() == 0) + if (formations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -175,7 +175,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable formations = formationService.GetFormationRealisee(asc, numPage, parPAge, idAgence, texte, tri); - if (formations.Count() == 0) + if (formations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -213,7 +213,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable formations = formationService.GetFormations(asc, numPage, parPAge, idAgence, texte, tri); - if (formations.Count() == 0) + if (formations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -243,7 +243,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable modeFormations = formationService.GetModesFormation(); - if (modeFormations.Count() == 0) + if (modeFormations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -273,7 +273,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable origineFormations = formationService.GetOriginesFormation(); - if (origineFormations.Count() == 0) + if (origineFormations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -311,7 +311,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable formations = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); - if (formations.Count() == 0) + if (formations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -341,7 +341,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable statutFormations = formationService.GetStatutsFormation(); - if (statutFormations.Count() == 0) + if (statutFormations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -371,7 +371,7 @@ namespace IO.Swagger.Controllers { //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ... IEnumerable typeFormations = formationService.GetTypesFormation(); - if (typeFormations.Count() == 0) + if (typeFormations == null) { ErreurDTO erreur = new ErreurDTO() { @@ -401,7 +401,7 @@ namespace IO.Swagger.Controllers [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "Acces interdit")] public virtual IActionResult UpdateFormation([FromBody] FormationDTO body, [FromRoute][Required] long? idFormation) { - FormationDTO formation = formationService.UpdateFormation(body); + FormationDTO formation = formationService.UpdateFormation(idFormation, body); if (formation == null) { formation = formationService.AddFormation(body); diff --git a/IServices/IFormationService.cs b/IServices/IFormationService.cs index dbe8278..2e5b0c5 100644 --- a/IServices/IFormationService.cs +++ b/IServices/IFormationService.cs @@ -10,7 +10,7 @@ namespace EPAServeur.IServices { public interface IFormationService { - FormationDTO GetFormationById(long? id); + FormationDTO GetFormationById(long? idFormation); 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); @@ -22,7 +22,7 @@ namespace EPAServeur.IServices IEnumerable GetTypesFormation(); FormationDTO AddFormation(FormationDTO formationDTO); - FormationDTO UpdateFormation(FormationDTO formationDTO); - bool DeleteFormationById(long? id); + FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO); + bool DeleteFormationById(long? idFormation); } } diff --git a/Services/FormationService.cs b/Services/FormationService.cs index 775bf3d..6d1a36a 100644 --- a/Services/FormationService.cs +++ b/Services/FormationService.cs @@ -35,15 +35,15 @@ namespace EPAServeur.Services /// /// Récupérer une formation par son id /// - /// + /// /// - public FormationDTO GetFormationById(long? id) + public FormationDTO GetFormationById(long? idFormation) { 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); + .FirstOrDefault(formation => formation.Id == idFormation); if (formation == null) return null; @@ -106,7 +106,7 @@ namespace EPAServeur.Services if (formations == null) - return new List(); + return null; formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); @@ -150,7 +150,7 @@ namespace EPAServeur.Services .Include(formation => formation.TypeFormation); if (formations == null) - return new List(); + return null; formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); @@ -214,7 +214,7 @@ namespace EPAServeur.Services if (formations == null) - return new List(); + return null; formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); @@ -268,7 +268,7 @@ namespace EPAServeur.Services } if (formations == null) - return new List(); + return null; formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); @@ -292,6 +292,9 @@ namespace EPAServeur.Services throw; } + if (modeFormations == null) + return null; + modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); return modeFormationDTOs; @@ -315,6 +318,9 @@ namespace EPAServeur.Services throw; } + if (origineFormations == null) + return null; + origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); return origineFormationDTOs; @@ -339,6 +345,9 @@ namespace EPAServeur.Services throw; } + if (statutFormations == null) + return null; + statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); return statutFormationDTOs; @@ -362,6 +371,9 @@ namespace EPAServeur.Services throw; } + if (typeFormations == null) + return null; + typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); return typeFormationDTOs; @@ -404,9 +416,9 @@ namespace EPAServeur.Services /// /// /// - public FormationDTO UpdateFormation(FormationDTO formationDTO) + public FormationDTO UpdateFormation(long? idFormation, FormationDTO formationDTO) { - Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == formationDTO.Id); + Formation formation = epContext.Formation.Find(idFormation); if (formation == null) { @@ -429,11 +441,11 @@ namespace EPAServeur.Services /// /// Supprimer une formation /// - /// + /// /// - public bool DeleteFormationById(long? id) + public bool DeleteFormationById(long? idFormation) { - Formation formation = epContext.Formation.FirstOrDefault(formation => formation.Id == id); + Formation formation = epContext.Formation.Find(idFormation); if (formation == null) return false;