Merge branch 'move_folder' into develop

develop
jboinembalome 4 years ago
commit 61f0effc51
  1. 3
      .gitignore
  2. 188
      EPAServeur.Tests/Controllers/FormationApiTests.cs
  3. 6
      EPAServeur.Tests/EPAServeur.Tests.csproj
  4. 1237
      EPAServeur.Tests/Services/FormationServiceTests.cs
  5. 52
      EPAServeur/Context/DataSeeder.cs
  6. 18
      EPAServeur/Controllers/FormationsApi.cs
  7. 16
      EPAServeur/IServices/IFormationService.cs
  8. 136
      EPAServeur/Services/FormationService.cs

3
.gitignore vendored

@ -6,6 +6,9 @@
# LOGS EPA SERVEUR # LOGS EPA SERVEUR
/EPAServeurLog /EPAServeurLog
# RAPPORT COUVERTURE DE CODE TESTS UNITAIRES
EPAServeurCoverageReport/
# User-specific files # User-specific files
*.rsuser *.rsuser
*.suo *.suo

@ -0,0 +1,188 @@
using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.Models.Formation;
using EPAServeur.Services;
using IO.Swagger.Controllers;
using IO.Swagger.DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Tests.Controllers
{
[TestFixture]
public class FormationApiTests
{
#region Variables
private FormationService formationService;
private readonly ILogger<FormationsApiController> logger;
#endregion
#region Setup
[SetUp]
public void Setup()
{
// Utilisation d'une base de données en mémoire
var optionBuider = new DbContextOptionsBuilder<EpContext>()
.UseInMemoryDatabase("server_ep_test")
.Options;
EpContext epContext = new EpContext(optionBuider);
epContext.Database.EnsureDeleted();
epContext.Database.EnsureCreated();
epContext.SaveChanges();
// Ajout du jeu de données pour les tests
DataSeeder.AddFormations(epContext);
// Détache les entités du context car la base de données InMemory créé des conflits
// entre les clés primaires lors d'un Update ou d'un Insert
foreach (var entity in epContext.ChangeTracker.Entries())
{
entity.State = EntityState.Detached;
}
// Instanciation du service qui sera utilisé dans le controleur
formationService = new FormationService(epContext);
}
#endregion
#region Tests GetFormationById
[Test]
public void GetFormationById_PasseEnParamUnIdPresentDansLaBDD_RetourneUnObjetOkResult()
{
// Arrange
FormationsApiController formationsApiController = new FormationsApiController(formationService, new NullLogger<FormationsApiController>());
// Act
var okResult = formationsApiController.GetFormationById(1);
// Assert
Assert.IsInstanceOf<OkObjectResult>(okResult.Result);
}
#endregion
#region Tests GetFormations
// Arrange
// Act
// Assert
#endregion
#region Tests GetFormationAnnulees
// Arrange
// Act
// Assert
#endregion
#region Tests GetFormationRealisee
// Arrange
// Act
// Assert
#endregion
#region Tests GetProchainesFormation
// Arrange
// Act
// Assert
#endregion
#region Tests GetModesFormation
// Arrange
// Act
// Assert
#endregion
#region Tests GetOriginesFormation
// Arrange
// Act
// Assert
#endregion
#region Tests GetStatutsFormation
// Arrange
// Act
// Assert
#endregion
#region Tests GetTypesFormation
// Arrange
// Act
// Assert
#endregion
#region Tests AddFormation
// Arrange
// Act
// Assert
#endregion
#region Tests UpdateFormation
// Arrange
// Act
// Assert
#endregion
#region Tests DeleteFormationById
// Arrange
// Act
// Assert
#endregion
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
@ -7,6 +7,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="nunit" Version="3.12.0" /> <PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />

File diff suppressed because it is too large Load Diff

@ -8,12 +8,12 @@ using System.Collections.Generic;
namespace EPAServeur.Context namespace EPAServeur.Context
{ {
/// <summary> /// <summary>
/// Classe permettant d'ajouter un jeu de données à un EpContext. /// Classe permettant d'insérer des données dans la base de données.
/// </summary> /// </summary>
public class DataSeeder public class DataSeeder
{ {
/// <summary> /// <summary>
/// Ajout des informations qui pourront être conservées dans la base de données /// Insère des informations qui pourront être conservées dans la base de données
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddInformationsDeBase(EpContext epContext) public static void AddInformationsDeBase(EpContext epContext)
@ -31,7 +31,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout des thèmes qui pourront être ajoutés et conservés /// Insère des thèmes qui pourront être ajoutés et conservés
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddThemes(EpContext epContext) public static void AddThemes(EpContext epContext)
@ -54,7 +54,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout d'un jeu de données fictif pour les types d'entretien /// Insère un jeu de données fictif pour les types d'entretien
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddTypesEntretien(EpContext epContext) public static void AddTypesEntretien(EpContext epContext)
@ -78,7 +78,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout d'un jeu de données fictif pour les ep /// Insère un jeu de données fictif pour les ep
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddEp(EpContext epContext) public static void AddEp(EpContext epContext)
@ -254,7 +254,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout d'un jeu de données fictif pour les engagements /// Insère un jeu de données fictif pour les engagements
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddEngagements(EpContext epContext) public static void AddEngagements(EpContext epContext)
@ -360,7 +360,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout d'un jeu de données fictif pour les formations /// Insère un jeu de données fictif pour les formations
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddFormations(EpContext epContext) public static void AddFormations(EpContext epContext)
@ -383,65 +383,65 @@ namespace EPAServeur.Context
//ModeFormation //ModeFormation
ModeFormation modeExterne, modeInterne, modePresentiel, modeELearning; ModeFormation modeExterne, modeInterne, modePresentiel, modeELearning;
modeExterne = new ModeFormation { Libelle = "Externe" }; modeExterne = new ModeFormation { Id = 1, Libelle = "Externe" };
epContext.ModeFormation.Add(modeExterne); epContext.ModeFormation.Add(modeExterne);
modeInterne = new ModeFormation { Libelle = "Interne" }; modeInterne = new ModeFormation { Id = 2, Libelle = "Interne" };
epContext.ModeFormation.Add(modeInterne); epContext.ModeFormation.Add(modeInterne);
modePresentiel = new ModeFormation { Libelle = "Présentiel" }; modePresentiel = new ModeFormation { Id = 3, Libelle = "Présentiel" };
epContext.ModeFormation.Add(modePresentiel); epContext.ModeFormation.Add(modePresentiel);
modeELearning = new ModeFormation { Libelle = "E-learning" }; modeELearning = new ModeFormation { Id = 4, Libelle = "E-learning" };
epContext.ModeFormation.Add(modeELearning); epContext.ModeFormation.Add(modeELearning);
//TypeFormation //TypeFormation
TypeFormation typeExterne, typeInterne, typeELearning, typeAcademy; TypeFormation typeExterne, typeInterne, typeELearning, typeAcademy;
typeExterne = new TypeFormation { Libelle = "Externe" }; typeExterne = new TypeFormation { Id = 1, Libelle = "Externe" };
epContext.TypeFormation.Add(typeExterne); epContext.TypeFormation.Add(typeExterne);
typeInterne = new TypeFormation { Libelle = "Interne" }; typeInterne = new TypeFormation { Id = 2, Libelle = "Interne" };
epContext.TypeFormation.Add(typeInterne); epContext.TypeFormation.Add(typeInterne);
typeELearning = new TypeFormation { Libelle = "E-learning" }; typeELearning = new TypeFormation { Id = 3, Libelle = "E-learning" };
epContext.TypeFormation.Add(typeELearning); epContext.TypeFormation.Add(typeELearning);
typeAcademy = new TypeFormation { Libelle = "Academy by Apside" }; typeAcademy = new TypeFormation { Id = 4, Libelle = "Academy by Apside" };
epContext.TypeFormation.Add(typeAcademy); epContext.TypeFormation.Add(typeAcademy);
//OrigineFormation //OrigineFormation
OrigineFormation origineFormationCollaborateur, origineFormationClient, origineFormationApside, origineFormationReglementaire; OrigineFormation origineFormationCollaborateur, origineFormationClient, origineFormationApside, origineFormationReglementaire;
origineFormationCollaborateur = new OrigineFormation { Libelle = "Demande collaborateur" }; origineFormationCollaborateur = new OrigineFormation { Id = 1, Libelle = "Demande collaborateur" };
epContext.OrigineFormation.Add(origineFormationCollaborateur); epContext.OrigineFormation.Add(origineFormationCollaborateur);
origineFormationClient = new OrigineFormation { Libelle = "Exigence client" }; origineFormationClient = new OrigineFormation { Id = 2, Libelle = "Exigence client" };
epContext.OrigineFormation.Add(origineFormationClient); epContext.OrigineFormation.Add(origineFormationClient);
origineFormationApside = new OrigineFormation { Libelle = "Exigence Apside" }; origineFormationApside = new OrigineFormation { Id = 3, Libelle = "Exigence Apside" };
epContext.OrigineFormation.Add(origineFormationApside); epContext.OrigineFormation.Add(origineFormationApside);
origineFormationReglementaire = new OrigineFormation { Libelle = "Formation réglementaire" }; origineFormationReglementaire = new OrigineFormation { Id = 4, Libelle = "Formation réglementaire" };
epContext.OrigineFormation.Add(origineFormationReglementaire); epContext.OrigineFormation.Add(origineFormationReglementaire);
//OrigineDemandeFormation //OrigineDemandeFormation
OrigineDemandeFormation origineDemandeFormationCollaborateur, origineDemandeFormationEP, OrigineDemandeFormation origineDemandeFormationCollaborateur, origineDemandeFormationEP,
origineDemandeFormationClient, origineDemandeFormationReglement, origineDemandeFormationApside; origineDemandeFormationClient, origineDemandeFormationReglement, origineDemandeFormationApside;
origineDemandeFormationCollaborateur = new OrigineDemandeFormation { Libelle = "Demande collaborateur" }; origineDemandeFormationCollaborateur = new OrigineDemandeFormation { Id = 1, Libelle = "Demande collaborateur" };
epContext.OrigineDemandeFormation.Add(origineDemandeFormationCollaborateur); epContext.OrigineDemandeFormation.Add(origineDemandeFormationCollaborateur);
origineDemandeFormationEP = new OrigineDemandeFormation { Libelle = "Demande EP" }; origineDemandeFormationEP = new OrigineDemandeFormation { Id = 2, Libelle = "Demande EP" };
epContext.OrigineDemandeFormation.Add(origineDemandeFormationEP); epContext.OrigineDemandeFormation.Add(origineDemandeFormationEP);
origineDemandeFormationClient = new OrigineDemandeFormation { Libelle = "Exigence Client" }; origineDemandeFormationClient = new OrigineDemandeFormation { Id = 3, Libelle = "Exigence Client" };
epContext.OrigineDemandeFormation.Add(origineDemandeFormationClient); epContext.OrigineDemandeFormation.Add(origineDemandeFormationClient);
origineDemandeFormationReglement = new OrigineDemandeFormation { Libelle = "Formation réglementaire" }; origineDemandeFormationReglement = new OrigineDemandeFormation { Id = 4, Libelle = "Formation réglementaire" };
epContext.OrigineDemandeFormation.Add(origineDemandeFormationReglement); epContext.OrigineDemandeFormation.Add(origineDemandeFormationReglement);
origineDemandeFormationApside = new OrigineDemandeFormation { Libelle = "Demande Apside" }; origineDemandeFormationApside = new OrigineDemandeFormation { Id = 5, Libelle = "Demande Apside" };
epContext.OrigineDemandeFormation.Add(origineDemandeFormationApside); epContext.OrigineDemandeFormation.Add(origineDemandeFormationApside);
//Formation //Formation
@ -661,7 +661,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout d'un jeu de données fictif pour les champs /// Insère un jeu de données fictif pour les champs
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddChamps(EpContext epContext) public static void AddChamps(EpContext epContext)
@ -822,7 +822,7 @@ namespace EPAServeur.Context
} }
/// <summary> /// <summary>
/// Ajout d'un jeu de données fictif pour les notes /// Insère un jeu de données fictif pour les notes
/// </summary> /// </summary>
/// <param name="epContext"></param> /// <param name="epContext"></param>
public static void AddNotes(EpContext epContext) public static void AddNotes(EpContext epContext)

@ -101,6 +101,10 @@ namespace IO.Swagger.Controllers
FormationDTO formation = await formationService.DeleteFormationByIdAsync(idFormation); FormationDTO formation = await formationService.DeleteFormationByIdAsync(idFormation);
} }
catch (FormationIncompatibleIdException)
{
logger.LogError("Impossible de supprimer la formation car l'id de la formation passé en paramètre est null.");
}
catch (FormationNotFoundException) catch (FormationNotFoundException)
{ {
logger.LogError("Impossible de supprimer la formation d'id {idFormation} car elle n'existe pas.", idFormation); logger.LogError("Impossible de supprimer la formation d'id {idFormation} car elle n'existe pas.", idFormation);
@ -213,6 +217,10 @@ namespace IO.Swagger.Controllers
{ {
formationDTO = await formationService.GetFormationByIdAsync(idFormation); formationDTO = await formationService.GetFormationByIdAsync(idFormation);
} }
catch (ArgumentNullException)
{
logger.LogError("L'argument passé dans la requête pour récupérer une formation est invalide.");
}
catch (FormationNotFoundException) catch (FormationNotFoundException)
{ {
logger.LogError("Aucune formation ne correspond à l'id {idFormation} recherchée.", idFormation); logger.LogError("Aucune formation ne correspond à l'id {idFormation} recherchée.", idFormation);
@ -225,14 +233,6 @@ namespace IO.Swagger.Controllers
return NotFound(erreurDTO); return NotFound(erreurDTO);
} }
catch (DbUpdateConcurrencyException)
{
logger.LogWarning("La formation {idFormation} n'a pas pu être récupérée car elle est prise par une autre ressource.", idFormation);
}
catch (DbUpdateException)
{
logger.LogError("Une erreur a eu lieu, la formation {idFormation} n'a pas pu être récupérée.", idFormation);
}
catch (Exception) catch (Exception)
{ {
logger.LogError("Une erreur inconnue est survenue lors de la récupération de la formation {idFormation}.", idFormation); logger.LogError("Une erreur inconnue est survenue lors de la récupération de la formation {idFormation}.", idFormation);
@ -272,7 +272,7 @@ namespace IO.Swagger.Controllers
try try
{ {
formations = await formationService.GetFormationRealiseeAsync(asc, numPage, parPAge, idAgence, texte, tri); formations = await formationService.GetFormationRealiseesAsync(asc, numPage, parPAge, idAgence, texte, tri);
} }
catch (ArgumentNullException) catch (ArgumentNullException)
{ {

@ -12,14 +12,14 @@ namespace EPAServeur.IServices
{ {
FormationDTO GetFormationById(long? idFormation); FormationDTO GetFormationById(long? idFormation);
Task<FormationDTO> GetFormationByIdAsync(long? idFormation); Task<FormationDTO> GetFormationByIdAsync(long? idFormation);
IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri); IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri); Task<IEnumerable<FormationDTO>> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri);
IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); Task<IEnumerable<FormationDTO>> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri);
IEnumerable<FormationDTO> GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetFormationRealiseeAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); Task<IEnumerable<FormationDTO>> GetFormationRealiseesAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri);
IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri);
Task<IEnumerable<FormationDTO>> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri); Task<IEnumerable<FormationDTO>> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri);
IEnumerable<ModeFormationDTO> GetModesFormation(); IEnumerable<ModeFormationDTO> GetModesFormation();
Task<IEnumerable<ModeFormationDTO>> GetModesFormationAsync(); Task<IEnumerable<ModeFormationDTO>> GetModesFormationAsync();
IEnumerable<OrigineFormationDTO> GetOriginesFormation(); IEnumerable<OrigineFormationDTO> GetOriginesFormation();

@ -82,7 +82,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri) public IEnumerable<FormationDTO> GetFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -129,10 +129,6 @@ namespace EPAServeur.Services
.Include(formation => formation.TypeFormation).Skip(skip).Take(take); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -148,7 +144,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<FormationDTO>> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri) public async Task<IEnumerable<FormationDTO>> GetFormationsAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -199,10 +195,6 @@ namespace EPAServeur.Services
} }
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -218,7 +210,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) public IEnumerable<FormationDTO> GetFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -244,9 +236,6 @@ namespace EPAServeur.Services
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).Skip(skip).Take(take); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -262,7 +251,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<FormationDTO>> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) public async Task<IEnumerable<FormationDTO>> GetFormationAnnuleesAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -288,9 +277,6 @@ namespace EPAServeur.Services
.Include(formation => formation.Origine) .Include(formation => formation.Origine)
.Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -306,7 +292,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public IEnumerable<FormationDTO> GetFormationRealisee(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) public IEnumerable<FormationDTO> GetFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -340,10 +326,6 @@ namespace EPAServeur.Services
} }
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -359,7 +341,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<FormationDTO>> GetFormationRealiseeAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) public async Task<IEnumerable<FormationDTO>> GetFormationRealiseesAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -392,10 +374,6 @@ namespace EPAServeur.Services
.Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -411,7 +389,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) public IEnumerable<FormationDTO> GetProchainesFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -442,9 +420,6 @@ namespace EPAServeur.Services
.Include(formation => formation.TypeFormation).Skip(skip).Take(take); .Include(formation => formation.TypeFormation).Skip(skip).Take(take);
} }
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -460,7 +435,7 @@ namespace EPAServeur.Services
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param> /// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param> /// <param name="tri">Colonne du tableau sur lequel le tri s&#x27;effectue</param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<FormationDTO>> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, int? idAgence, string texte, string tri) public async Task<IEnumerable<FormationDTO>> GetProchainesFormationAsync(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri)
{ {
IEnumerable<Formation> formations; IEnumerable<Formation> formations;
IEnumerable<FormationDTO> formationDTOs; IEnumerable<FormationDTO> formationDTOs;
@ -492,9 +467,6 @@ namespace EPAServeur.Services
.Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync(); .Include(formation => formation.TypeFormation).Skip(skip).Take(take).ToListAsync();
} }
if (formations == null)
return null;
formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation)); formationDTOs = formations.Where(formation => formation.Intitule.ToLower().Contains(texte)).Select(formation => GetFormationDTO(formation));
return formationDTOs; return formationDTOs;
@ -511,9 +483,6 @@ namespace EPAServeur.Services
modeFormations = epContext.ModeFormation; modeFormations = epContext.ModeFormation;
if (modeFormations == null)
return null;
modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation));
return modeFormationDTOs; return modeFormationDTOs;
@ -529,9 +498,6 @@ namespace EPAServeur.Services
IEnumerable<ModeFormationDTO> modeFormationDTOs; IEnumerable<ModeFormationDTO> modeFormationDTOs;
modeFormations = await epContext.ModeFormation.ToListAsync(); modeFormations = await epContext.ModeFormation.ToListAsync();
if (modeFormations == null)
return null;
modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation));
return modeFormationDTOs; return modeFormationDTOs;
@ -548,9 +514,6 @@ namespace EPAServeur.Services
origineFormations = epContext.OrigineFormation; origineFormations = epContext.OrigineFormation;
if (origineFormations == null)
return null;
origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation));
return origineFormationDTOs; return origineFormationDTOs;
@ -567,9 +530,6 @@ namespace EPAServeur.Services
origineFormations = await epContext.OrigineFormation.ToListAsync(); origineFormations = await epContext.OrigineFormation.ToListAsync();
if (origineFormations == null)
return null;
origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation));
return origineFormationDTOs; return origineFormationDTOs;
@ -586,9 +546,6 @@ namespace EPAServeur.Services
statutFormations = epContext.StatutFormation; statutFormations = epContext.StatutFormation;
if (statutFormations == null)
return null;
statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation));
return statutFormationDTOs; return statutFormationDTOs;
@ -605,9 +562,6 @@ namespace EPAServeur.Services
statutFormations = await epContext.StatutFormation.ToListAsync(); statutFormations = await epContext.StatutFormation.ToListAsync();
if (statutFormations == null)
return null;
statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation));
return statutFormationDTOs; return statutFormationDTOs;
@ -624,9 +578,6 @@ namespace EPAServeur.Services
typeFormations = epContext.TypeFormation; typeFormations = epContext.TypeFormation;
if (typeFormations == null)
return null;
typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation));
return typeFormationDTOs; return typeFormationDTOs;
@ -643,9 +594,6 @@ namespace EPAServeur.Services
typeFormations = await epContext.TypeFormation.ToListAsync(); typeFormations = await epContext.TypeFormation.ToListAsync();
if (typeFormations == null)
return null;
typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation));
return typeFormationDTOs; return typeFormationDTOs;
@ -664,9 +612,7 @@ namespace EPAServeur.Services
Formation formation = new Formation(); Formation formation = new Formation();
formation = SetFormation(formation, formationDTO); formation = SetFormation(formation, formationDTO);
if (formation.Statut != null) epContext.StatutFormation.Attach(formation.Statut);
epContext.StatutFormation.Attach(formation.Statut);
epContext.OrigineFormation.Attach(formation.Origine); epContext.OrigineFormation.Attach(formation.Origine);
epContext.ModeFormation.Attach(formation.ModeFormation); epContext.ModeFormation.Attach(formation.ModeFormation);
epContext.TypeFormation.Attach(formation.TypeFormation); epContext.TypeFormation.Attach(formation.TypeFormation);
@ -684,15 +630,13 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
public async Task<FormationDTO> AddFormationAsync(FormationDTO formationDTO) public async Task<FormationDTO> AddFormationAsync(FormationDTO formationDTO)
{ {
if (!IsFormationValide(formationDTO)) if (!await IsFormationValideAsync(formationDTO))
throw new FormationInvalidException(); throw new FormationInvalidException();
Formation formation = new Formation(); Formation formation = new Formation();
formation = SetFormation(formation, formationDTO); formation = SetFormation(formation, formationDTO);
if (formation.Statut != null) epContext.StatutFormation.Attach(formation.Statut);
epContext.StatutFormation.Attach(formation.Statut);
epContext.OrigineFormation.Attach(formation.Origine); epContext.OrigineFormation.Attach(formation.Origine);
epContext.ModeFormation.Attach(formation.ModeFormation); epContext.ModeFormation.Attach(formation.ModeFormation);
epContext.TypeFormation.Attach(formation.TypeFormation); epContext.TypeFormation.Attach(formation.TypeFormation);
@ -714,10 +658,10 @@ namespace EPAServeur.Services
if (!IsFormationValide(formationDTO)) if (!IsFormationValide(formationDTO))
throw new FormationInvalidException(); throw new FormationInvalidException();
if (formationDTO == null && !formationDTO.Id.HasValue && formationDTO.Id.Value != idFormation) if (!formationDTO.Id.HasValue || formationDTO.Id.Value != idFormation)
throw new FormationIncompatibleIdException(); throw new FormationIncompatibleIdException();
Formation formation = epContext.Formation.Find(idFormation); Formation formation = epContext.Formation.Find(idFormation.Value);
if (formation == null) if (formation == null)
return null; return null;
@ -740,10 +684,10 @@ namespace EPAServeur.Services
if (!IsFormationValide(formationDTO)) if (!IsFormationValide(formationDTO))
throw new FormationInvalidException(); throw new FormationInvalidException();
if (formationDTO == null && !formationDTO.Id.HasValue && formationDTO.Id.Value != idFormation) if (!formationDTO.Id.HasValue || formationDTO.Id.Value != idFormation)
throw new FormationIncompatibleIdException(); throw new FormationIncompatibleIdException();
Formation formation = await epContext.Formation.FindAsync(idFormation); Formation formation = await epContext.Formation.FindAsync(idFormation.Value);
if (formation == null) if (formation == null)
return null; return null;
@ -761,14 +705,17 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
public FormationDTO DeleteFormationById(long? idFormation) public FormationDTO DeleteFormationById(long? idFormation)
{ {
Formation formation = epContext.Formation.Find(idFormation); if (!idFormation.HasValue)
throw new FormationIncompatibleIdException();
Formation formation = epContext.Formation.Find(idFormation.Value);
if (formation == null) if (formation == null)
throw new FormationNotFoundException(); throw new FormationNotFoundException();
epContext.Remove(formation); epContext.Remove(formation);
epContext.SaveChanges(); epContext.SaveChanges();
return GetFormationDTO(formation); return GetFormationDTO(formation);
@ -781,7 +728,10 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
public async Task<FormationDTO> DeleteFormationByIdAsync(long? idFormation) public async Task<FormationDTO> DeleteFormationByIdAsync(long? idFormation)
{ {
Formation formation = await epContext.Formation.FindAsync(idFormation); if (!idFormation.HasValue)
throw new FormationIncompatibleIdException();
Formation formation = await epContext.Formation.FindAsync(idFormation.Value);
if (formation == null) if (formation == null)
throw new FormationNotFoundException(); throw new FormationNotFoundException();
@ -798,14 +748,40 @@ namespace EPAServeur.Services
/// <summary> /// <summary>
/// Vérifier si un objet FormationDTO est valide pour ajout ou mise à jour /// Vérifier si un objet FormationDTO est valide pour ajout ou mise à jour
/// </summary> /// </summary>
/// <remarks> Un objet FormationDTO est valide si aucune de ses propriétés n'est à null</remarks> /// <remarks> Un objet FormationDTO est valide si aucune de ses propriétés n'est à null,si la date de début de la formation est inférieur à la date de fin et si le statut, l'origine,le mode et le type sont présents dans la base de données</remarks>
/// <param name="formation"></param> /// <param name="formation"></param>
/// <returns>true si l'objet est valide, false sinon</returns> /// <returns>true si l'objet est valide, false sinon</returns>
private bool IsFormationValide(FormationDTO formation) private bool IsFormationValide(FormationDTO formation)
{ {
return !(formation == null || formation.IdAgence == null || formation.Intitule == null || formation.Organisme == null); return !(formation == null || formation.Statut == null || formation.Mode == null || formation.Origine == null || formation.Type == null
|| !formation.IdAgence.HasValue || formation.IdAgence == 0
|| string.IsNullOrWhiteSpace(formation.Intitule) || string.IsNullOrWhiteSpace(formation.Organisme)
|| !formation.DateDebut.HasValue || !formation.DateFin.HasValue || formation.DateDebut.Value > formation.DateFin.Value
|| !formation.Statut.Id.HasValue || !formation.Mode.Id.HasValue || !formation.Origine.Id.HasValue || !formation.Type.Id.HasValue
|| !epContext.StatutFormation.Any(statut => statut.Id == formation.Statut.Id.Value && statut.Libelle == formation.Statut.Libelle)
|| !epContext.ModeFormation.Any(mode => mode.Id == formation.Mode.Id.Value && mode.Libelle == formation.Mode.Libelle)
|| !epContext.OrigineFormation.Any(origine => origine.Id == formation.Origine.Id.Value && origine.Libelle == formation.Origine.Libelle)
|| !epContext.TypeFormation.Any(type => type.Id == formation.Type.Id.Value && type.Libelle == formation.Type.Libelle));
} }
/// <summary>
/// Vérifier si un objet FormationDTO est valide pour ajout ou mise à jour
/// </summary>
/// <remarks> Un objet FormationDTO est valide si aucune de ses propriétés n'est à null,si la date de début de la formation est inférieur à la date de fin et si le statut, l'origine,le mode et le type sont présents dans la base de données</remarks>
/// <param name="formation"></param>
/// <returns>true si l'objet est valide, false sinon</returns>
private async Task<bool> IsFormationValideAsync(FormationDTO formation)
{
return !(formation == null || formation.Statut == null || formation.Mode == null || formation.Origine == null || formation.Type == null
|| !formation.IdAgence.HasValue || formation.IdAgence == 0
|| string.IsNullOrWhiteSpace(formation.Intitule) || string.IsNullOrWhiteSpace(formation.Organisme)
|| !formation.DateDebut.HasValue || !formation.DateFin.HasValue || formation.DateDebut.Value > formation.DateFin.Value
|| !formation.Statut.Id.HasValue || !formation.Mode.Id.HasValue || !formation.Origine.Id.HasValue || !formation.Type.Id.HasValue
|| ! await epContext.StatutFormation.AnyAsync(statut => statut.Id == formation.Statut.Id.Value && statut.Libelle == formation.Statut.Libelle)
|| ! await epContext.ModeFormation.AnyAsync(mode => mode.Id == formation.Mode.Id.Value && mode.Libelle == formation.Mode.Libelle)
|| ! await epContext.OrigineFormation.AnyAsync(origine => origine.Id == formation.Origine.Id.Value && origine.Libelle == formation.Origine.Libelle)
|| ! await epContext.TypeFormation.AnyAsync(type => type.Id == formation.Type.Id.Value && type.Libelle == formation.Type.Libelle));
}
#region Object to DTO #region Object to DTO
/// <summary> /// <summary>
/// Récupère un objet FormationDTO en fonction d'un objet Formation /// Récupère un objet FormationDTO en fonction d'un objet Formation
@ -936,8 +912,6 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO) private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO)
{ {
if (origineFormationDTO == null)
return null;
OrigineFormation origineFormation = new OrigineFormation() OrigineFormation origineFormation = new OrigineFormation()
{ {
Id = origineFormationDTO.Id.Value, Id = origineFormationDTO.Id.Value,
@ -953,8 +927,6 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO) private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO)
{ {
if (statutFormationDTO == null)
return null;
StatutFormation statutFormation = new StatutFormation() StatutFormation statutFormation = new StatutFormation()
{ {
Id = statutFormationDTO.Id.Value, Id = statutFormationDTO.Id.Value,
@ -970,8 +942,6 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO) private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO)
{ {
if (modeFormationDTO == null)
return null;
ModeFormation modeFormation = new ModeFormation() ModeFormation modeFormation = new ModeFormation()
{ {
Id = modeFormationDTO.Id.Value, Id = modeFormationDTO.Id.Value,
@ -987,8 +957,6 @@ namespace EPAServeur.Services
/// <returns></returns> /// <returns></returns>
private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO) private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO)
{ {
if (typeFormationDTO == null)
return null;
TypeFormation typeFormation = new TypeFormation() TypeFormation typeFormation = new TypeFormation()
{ {
Id = typeFormationDTO.Id.Value, Id = typeFormationDTO.Id.Value,

Loading…
Cancel
Save