Merge branch 'participation_formation' into develop

develop
jboinembalome 4 years ago
commit 9949eee8d2
  1. 310
      EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs
  2. 16
      EPAServeur/Context/DataSeeder.cs
  3. 4
      EPAServeur/Context/EpContext.cs
  4. 222
      EPAServeur/Controllers/ParticipationsFormationsApi.cs
  5. 3
      EPAServeur/DTO/EvaluationDTO.cs
  6. 5
      EPAServeur/DTO/SaisieDTO.cs
  7. 40
      EPAServeur/Exceptions/ParticipationFormationIncompatibleIdException.cs
  8. 40
      EPAServeur/Exceptions/ParticipationFormationInvalidException.cs
  9. 40
      EPAServeur/Exceptions/ParticipationFormationNotFoundException.cs
  10. 17
      EPAServeur/IServices/IParticipationFormationService.cs
  11. 5
      EPAServeur/Models/Formation/ParticipationFormation.cs
  12. 2
      EPAServeur/Models/SaisieChamp/Champ.cs
  13. 370
      EPAServeur/Services/ParticipationFormationService.cs
  14. 1
      EPAServeur/Startup.cs

@ -0,0 +1,310 @@
using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.IServices;
using EPAServeur.Models.Formation;
using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Tests.Services
{
[TestFixture]
public class ParticipationFormationServiceTests
{
#region Variables
private EpContext epContext;
private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService;
#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 = new EpContext(optionBuider);
collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, epContext);
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;
}
}
#endregion
#region Tests GetEvaluationCollaborateurAsync
[Test]
public async Task GetEvaluationCollaborateurAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneEvaluation()
{
// Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService);
int idParticipationFormation = 5;
// Act
EvaluationDTO evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation);
// Assert
Assert.AreEqual(idParticipationFormation, evaluationDTO.Id);
Assert.AreEqual(new DateTime(2020, 5, 25, 14, 0, 0), evaluationDTO.DateDebut);
Assert.True(evaluationDTO.EstCertifie);
Assert.AreEqual("Apprendre C# et le développement de logiciels avec WPF", evaluationDTO.Intitule);
}
[TestCase(-1)]
[TestCase(0)]
[TestCase(999999)]
public void GetEvaluationCollaborateurAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneParticipationFormationNotFoundException(long idParticipationFormation)
{
// Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService);
// Act
AsyncTestDelegate throwException = () => participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation);
// Assert
Assert.ThrowsAsync(typeof(ParticipationFormationNotFoundException), throwException);
}
#endregion
#region Tests GetParticipationByCollaborateur
[TestCase("842650db-a548-4472-a3af-4c5fff3c1ab8")]
[TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")]
public async Task GetParticipationByCollaborateur_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur)
{
// Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService);
// Act
IEnumerable<ParticipationFormationDTO> participationFormationDTOs = await participationFormationService.GetParticipationByCollaborateurAsync(idCollaborateur);
// Assert
Assert.Less(0, participationFormationDTOs.Count());
}
[TestCase("e7820f92-eab1-42f5-ae96-5c16e71ff1e6")]
[TestCase("b5254c6c-7caa-435f-a4bb-e0cf92559832")]
public async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(Guid idCollaborateur)
{
// Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService);
// Act
IEnumerable<ParticipationFormationDTO> participationFormationDTOs = await participationFormationService.GetParticipationByCollaborateurAsync(idCollaborateur);
// Assert
Assert.AreEqual(0, participationFormationDTOs.Count());
}
#endregion
/*
#region Tests UpdateFormationAsync
[TestCase(1, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")]
public async Task UpdateFormationAsync_ModifieUneFormationValide_FormationModifieeAvecSucces(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode)
.Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault();
StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut)
.Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault();
TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType)
.Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault();
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault();
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation);
formation.Intitule = intitule;
formation.IdAgence = idAgence;
formation.DateDebut = dateDebut;
formation.DateFin = dateFin;
formation.Heure = 2;
formation.Jour = 1;
formation.Mode = modeExterne;
formation.Type = typeELearning;
formation.Organisme = organisme;
formation.Origine = origineFormationCollaborateur;
formation.Statut = statutPlanifie;
formation.EstCertifiee = false;
// Act
FormationDTO formationModifie = await formationService.UpdateFormationAsync(idFormation, formation);
// Assert
Assert.IsNotNull(formationModifie);
Assert.AreEqual(idFormation, formationModifie.Id);
Assert.AreEqual(formation.Intitule, formationModifie.Intitule);
Assert.AreEqual(formation.IdAgence, formationModifie.IdAgence);
Assert.AreEqual(formation.DateDebut, formationModifie.DateDebut);
Assert.AreEqual(formation.DateFin, formationModifie.DateFin);
Assert.AreEqual(formation.Heure, formationModifie.Heure);
Assert.AreEqual(formation.Jour, formationModifie.Jour);
Assert.AreEqual(formation.Mode, formationModifie.Mode);
Assert.AreEqual(formation.Type, formationModifie.Type);
Assert.AreEqual(formation.Organisme, formationModifie.Organisme);
Assert.AreEqual(formation.Origine, formationModifie.Origine);
Assert.AreEqual(formation.Statut, formationModifie.Statut);
Assert.AreEqual(formation.EstCertifiee, formationModifie.EstCertifiee);
}
[TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-10-30")]
[TestCase(1, 0, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 0, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 0, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 0, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 0, "Test Formation", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 1, "", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, null, "Test Formation", "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 1, null, "Apside", "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 1, "Test Formation", null, "2020-10-31", "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", null, "2020-11-02")]
[TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", null)]
public async Task UpdateFormationAsync_ModifieUneFormationAvecDesProprietesInvalides_LeveUneFormationInvalidException(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode)
.Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault();
StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut)
.Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault();
TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType)
.Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault();
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault();
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation);
formation.Intitule = intitule;
formation.IdAgence = idAgence;
formation.DateDebut = dateDebut;
formation.DateFin = dateFin;
formation.Heure = 2;
formation.Jour = 1;
formation.Mode = modeExterne;
formation.Type = typeELearning;
formation.Organisme = organisme;
formation.Origine = origineFormationCollaborateur;
formation.Statut = statutPlanifie;
formation.EstCertifiee = false;
// Act
AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(idFormation, formation);
// Assert
Assert.ThrowsAsync(typeof(FormationInvalidException), throwException);
}
[TestCase(2, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")]
[TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")]
[TestCase(null, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")]
public async Task UpdateFormationAsync_ModifieUneFormationAvecUnIdIncorrecte_LeveUneFormationIncompatibleIdException(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode)
.Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault();
StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut)
.Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault();
TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType)
.Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault();
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault();
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = await formationService.GetFormationByIdAsync(1);
formation.Id = idFormation;
formation.Intitule = intitule;
formation.IdAgence = idAgence;
formation.DateDebut = dateDebut;
formation.DateFin = dateFin;
formation.Heure = 2;
formation.Jour = 1;
formation.Mode = modeExterne;
formation.Type = typeELearning;
formation.Organisme = organisme;
formation.Origine = origineFormationCollaborateur;
formation.Statut = statutPlanifie;
formation.EstCertifiee = false;
// Act
AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(1, formation);
// Assert
Assert.ThrowsAsync(typeof(FormationIncompatibleIdException), throwException);
}
[TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")]
public void UpdateFormationAsync_ModifieUneFormationAvecUnIdInexistant_RetourneUnObjetNull(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode)
.Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault();
StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut)
.Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault();
TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType)
.Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault();
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault();
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = new FormationDTO
{
Id = idFormation,
Intitule = intitule,
IdAgence = idAgence,
DateDebut = dateDebut,
DateFin = dateFin,
Heure = 2,
Jour = 1,
Mode = modeExterne,
Type = typeELearning,
Organisme = organisme,
Origine = origineFormationCollaborateur,
Statut = statutPlanifie,
EstCertifiee = false
};
// Act
AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(idFormation, formation);
// Assert
Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException);
}
#endregion
*/
}
}

@ -1253,10 +1253,10 @@ namespace EPAServeur.Context
// Participation formation
ParticipationFormation p1, p2, p3, p4;
//ParticipationFormation p1, p2, p3, p4;
ParticipationFormation p5, p6, p7, p8;
ParticipationFormation p9, p10, p11, p12;
//ParticipationFormation p9, p10, p11, p12;
/*
p1 = new ParticipationFormation
{
@ -1301,13 +1301,12 @@ namespace EPAServeur.Context
Formation = f3
};
epContext.ParticipationFormation.Add(p4);
*/
p5 = new ParticipationFormation
{
IdParticipationFormation = 5,
DateCreation = new DateTime(2020, 5, 25, 9, 0, 0),
EstEvaluee = false,
IdDemandeFormation = d5.IdDemandeFormation,
DemandeFormation = d5,
Formation = f3
};
@ -1318,7 +1317,6 @@ namespace EPAServeur.Context
IdParticipationFormation = 6,
DateCreation = new DateTime(2020, 6, 25, 9, 0, 0),
EstEvaluee = false,
IdDemandeFormation = d6.IdDemandeFormation,
DemandeFormation = d6,
Formation = f4
};
@ -1329,7 +1327,6 @@ namespace EPAServeur.Context
IdParticipationFormation = 7,
DateCreation = new DateTime(2020, 7, 25, 9, 0, 0),
EstEvaluee = false,
IdDemandeFormation = d7.IdDemandeFormation,
DemandeFormation = d7,
Formation = f4
};
@ -1340,12 +1337,11 @@ namespace EPAServeur.Context
IdParticipationFormation = 8,
DateCreation = new DateTime(2020, 8, 25, 9, 0, 0),
EstEvaluee = false,
IdDemandeFormation = d8.IdDemandeFormation,
DemandeFormation = d8,
Formation = f5
};
epContext.ParticipationFormation.Add(p8);
/*
p9 = new ParticipationFormation
{
IdParticipationFormation = 9,
@ -1390,7 +1386,7 @@ namespace EPAServeur.Context
};
epContext.ParticipationFormation.Add(p12);
*/
epContext.SaveChanges();
}

@ -154,6 +154,8 @@ namespace EPAServeur.Context
{
entity.HasKey(e => e.IdDemandeFormation);
entity.Property(e => e.IdDemandeFormation).ValueGeneratedOnAdd();
entity.HasOne<ParticipationFormation>(e => e.ParticipationFormation).WithOne(e => e.DemandeFormation).HasForeignKey<ParticipationFormation>(d => d.IdParticipationFormation);
});
modelBuilder.Entity<Formation>(entity =>
@ -189,8 +191,6 @@ namespace EPAServeur.Context
entity.HasKey(e => e.IdParticipationFormation);
entity.Property(e => e.IdParticipationFormation).ValueGeneratedOnAdd();
entity.HasMany<Saisie>(e => e.Evaluation).WithOne(e => e.ParticipationFormation);
entity.HasOne<DemandeFormation>(e => e.DemandeFormation).WithOne(a => a.ParticipationFormation).HasForeignKey<DemandeFormation>(a => a.IdDemandeFormation);
});
modelBuilder.Entity<StatutFormation>(entity =>

@ -18,6 +18,14 @@ using IO.Swagger.Attributes;
using IO.Swagger.Security;
using Microsoft.AspNetCore.Authorization;
using IO.Swagger.DTO;
using EPAServeur.IServices;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
using EPAServeur.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace IO.Swagger.Controllers
{
@ -27,6 +35,17 @@ namespace IO.Swagger.Controllers
[ApiController]
public class ParticipationsFormationsApiController : ControllerBase
{
private readonly IParticipationFormationService participationFormationService;
private readonly ILogger<ParticipationsFormationsApiController> logger;
private readonly IWebHostEnvironment env;
public ParticipationsFormationsApiController(IParticipationFormationService _participationFormationService, ILogger<ParticipationsFormationsApiController> _logger, IWebHostEnvironment _env)
{
participationFormationService = _participationFormationService;
logger = _logger;
env = _env;
}
/// <summary>
///
/// </summary>
@ -41,7 +60,7 @@ namespace IO.Swagger.Controllers
/// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpPut]
[Route("/api/participationsformation/{idParticipationFormation}/evaluation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("EvaluerFormation")]
[SwaggerResponse(statusCode: 200, type: typeof(EvaluationDTO), description: "Evaluation envoyée avec succès")]
@ -50,32 +69,95 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n&#x27;a pas été trouvée")]
[SwaggerResponse(statusCode: 415, type: typeof(ErreurDTO), description: "L’opération ne peut pas être effectuée car certaines données sont manquantes")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult EvaluerFormation([FromBody]EvaluationDTO body, [FromRoute][Required]long? idParticipationFormation)
public virtual async Task<IActionResult> EvaluerFormation([FromBody]EvaluationDTO body, [FromRoute][Required]long idParticipationFormation)
{
if (env.IsDevelopment())
logger.LogInformation("Mise à jour de la participation à la formation d'id {idParticipationFormation}.", idParticipationFormation);
try
{
body = await participationFormationService.EvaluerFormationAsync(idParticipationFormation, body);
}
catch (ParticipationFormationIncompatibleIdException e)
{
if (env.IsDevelopment())
logger.LogInformation(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status415UnsupportedMediaType,
Message = e.Message,
};
return StatusCode(erreur.Code.Value, erreur.Message);
}
catch (ParticipationFormationInvalidException e)
{
if (env.IsDevelopment())
logger.LogInformation(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status415UnsupportedMediaType,
Message = e.Message,
};
return StatusCode(erreur.Code.Value, erreur.Message);
}
catch (ParticipationFormationNotFoundException e)
{
if (env.IsDevelopment())
logger.LogInformation(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status404NotFound,
Message = e.Message
};
return NotFound(erreur);
}
catch (DbUpdateConcurrencyException e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
//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(EvaluationDTO));
Code = StatusCodes.Status500InternalServerError,
Message = string.Format("La participation à la formation {0} n'a pas pu être mise à jour car elle est prise par une autre ressource.", idParticipationFormation)
};
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
return StatusCode(erreur.Code.Value, erreur);
}
catch (DbUpdateException e)
{
logger.LogError(e.Message);
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur est survenue sur le serveur lors de la mise à jour de la participation à la formation."
};
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
return StatusCode(erreur.Code.Value, erreur);
}
catch (Exception e)
{
logger.LogError(e.Message);
//TODO: Uncomment the next line to return response 415 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(415, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur inconnue est survenue sur le serveur."
};
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "{\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 0,\n \"estCertifiee\" : true,\n \"intitule\" : \"intitule\",\n \"saisies\" : [ {\n \"note\" : 6,\n \"texte\" : \"texte\",\n \"id\" : \"id\",\n \"champ\" : {\n \"ordre\" : 6,\n \"texte\" : \"texte\",\n \"section\" : \"section\",\n \"soussection\" : \"soussection\",\n \"id\" : 3,\n \"typeSaisie\" : \"Commentaire\"\n }\n }, {\n \"note\" : 6,\n \"texte\" : \"texte\",\n \"id\" : \"id\",\n \"champ\" : {\n \"ordre\" : 6,\n \"texte\" : \"texte\",\n \"section\" : \"section\",\n \"soussection\" : \"soussection\",\n \"id\" : 3,\n \"typeSaisie\" : \"Commentaire\"\n }\n } ]\n}";
return StatusCode(erreur.Code.Value, erreur);
}
var example = exampleJson != null
? JsonConvert.DeserializeObject<EvaluationDTO>(exampleJson)
: default(EvaluationDTO); //TODO: Change the data returned
return new ObjectResult(example);
if (env.IsDevelopment())
logger.LogInformation("Update effectué avec succès");
return Ok(body);
}
/// <summary>
@ -90,7 +172,7 @@ namespace IO.Swagger.Controllers
/// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpGet]
[Route("/api/participationsformation/{idParticipationFormation}/evaluation")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetEvaluationCollaborateur")]
[SwaggerResponse(statusCode: 200, type: typeof(EvaluationDTO), description: "OK")]
@ -98,29 +180,47 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n&#x27;a pas été trouvée")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetEvaluationCollaborateur([FromRoute][Required]long? idParticipationFormation)
public virtual async Task<IActionResult> GetEvaluationCollaborateur([FromRoute][Required]long idParticipationFormation)
{
//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(EvaluationDTO));
if (env.IsDevelopment())
logger.LogInformation("Récupération de la participation à la formation {idParticipationFormation}.", idParticipationFormation);
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
EvaluationDTO evaluationDTO;
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
try
{
evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation);
}
catch (ParticipationFormationNotFoundException e)
{
if (env.IsDevelopment())
logger.LogInformation(e.Message);
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
ErreurDTO erreurDTO = new ErreurDTO()
{
Code = StatusCodes.Status404NotFound,
Message = e.Message
};
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "{\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 0,\n \"estCertifiee\" : true,\n \"intitule\" : \"intitule\",\n \"saisies\" : [ {\n \"note\" : 6,\n \"texte\" : \"texte\",\n \"id\" : \"id\",\n \"champ\" : {\n \"ordre\" : 6,\n \"texte\" : \"texte\",\n \"section\" : \"section\",\n \"soussection\" : \"soussection\",\n \"id\" : 3,\n \"typeSaisie\" : \"Commentaire\"\n }\n }, {\n \"note\" : 6,\n \"texte\" : \"texte\",\n \"id\" : \"id\",\n \"champ\" : {\n \"ordre\" : 6,\n \"texte\" : \"texte\",\n \"section\" : \"section\",\n \"soussection\" : \"soussection\",\n \"id\" : 3,\n \"typeSaisie\" : \"Commentaire\"\n }\n } ]\n}";
return NotFound(erreurDTO);
}
catch (Exception e)
{
logger.LogError(e.Message);
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur inconnue est survenue sur le serveur."
};
return StatusCode(erreur.Code.Value, erreur);
}
if (env.IsDevelopment())
logger.LogInformation("Participation à la formation {idParticipationFormation} récupérée.", idParticipationFormation);
var example = exampleJson != null
? JsonConvert.DeserializeObject<EvaluationDTO>(exampleJson)
: default(EvaluationDTO); //TODO: Change the data returned
return new ObjectResult(example);
return Ok(evaluationDTO);
}
/// <summary>
@ -128,11 +228,6 @@ namespace IO.Swagger.Controllers
/// </summary>
/// <remarks>Récupérer la liste des participations de formation d’un collaborateur.</remarks>
/// <param name="idCollaborateur">Id du collaborateur</param>
/// <param name="asc">Indique si les données sont récupérées dans l&#x27;ordre croissant ou non</param>
/// <param name="numPage">Numéro de la page du tableau à afficher</param>
/// <param name="parPAge">Nombre d’élément maximum à afficher dans le tableau</param>
/// <param name="texte">Texte permettant de filtrer les données</param>
/// <param name="tri">Colonne du tableau sur lequel le tri devra être effectué</param>
/// <response code="200">OK</response>
/// <response code="401">L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;est pas authentifié</response>
/// <response code="403">L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants</response>
@ -140,7 +235,7 @@ namespace IO.Swagger.Controllers
/// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpGet]
[Route("/api/participationsformation/{idCollaborateur}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
//[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState]
[SwaggerOperation("GetParticipationByCollaborateur")]
[SwaggerResponse(statusCode: 200, type: typeof(List<ParticipationFormationDTO>), description: "OK")]
@ -148,29 +243,34 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accéder à la ressource n’a pas les droits d’accès suffisants")]
[SwaggerResponse(statusCode: 404, type: typeof(ErreurDTO), description: "La ressource n&#x27;a pas été trouvée")]
[SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")]
public virtual IActionResult GetParticipationByCollaborateur([FromRoute][Required]Guid? idCollaborateur, [FromQuery]bool? asc, [FromQuery]int? numPage, [FromQuery][Range(5, 100)]int? parPAge, [FromQuery]string texte, [FromQuery]string tri)
public virtual async Task<IActionResult> GetParticipationByCollaborateur([FromRoute][Required]Guid idCollaborateur)
{
//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<ParticipationFormationDTO>));
if (env.IsDevelopment())
logger.LogInformation("Récupération de la liste des particicaptions aux formations d'un collaborateur.");
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(401, default(ErreurDTO));
IEnumerable<ParticipationFormationDTO> participationFormationDTOs;
//TODO: Uncomment the next line to return response 403 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(403, default(ErreurDTO));
try
{
participationFormationDTOs = await participationFormationService.GetParticipationByCollaborateurAsync(idCollaborateur);
}
catch (Exception e)
{
logger.LogError(e.Message);
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(ErreurDTO));
ErreurDTO erreur = new ErreurDTO()
{
Code = StatusCodes.Status500InternalServerError,
Message = "Une erreur inconnue est survenue sur le serveur."
};
return StatusCode(erreur.Code.Value, erreur);
}
//TODO: Uncomment the next line to return response 500 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(500, default(ErreurDTO));
string exampleJson = null;
exampleJson = "[ {\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 7,\n \"intitule\" : \"intitule\"\n}, {\n \"estEvaluee\" : true,\n \"dateCreation\" : \"2000-01-23T04:56:07.000+00:00\",\n \"dateDebut\" : \"2000-01-23T04:56:07.000+00:00\",\n \"id\" : 7,\n \"intitule\" : \"intitule\"\n} ]";
if (env.IsDevelopment())
logger.LogInformation("Liste des particicaptions aux formations d'un collaborateur récupérée.");
var example = exampleJson != null
? JsonConvert.DeserializeObject<List<ParticipationFormationDTO>>(exampleJson)
: default(List<ParticipationFormationDTO>); //TODO: Change the data returned
return new ObjectResult(example);
return Ok(participationFormationDTOs);
}
}
}

@ -17,6 +17,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using EPAServeur.Attributes;
namespace IO.Swagger.DTO
{
@ -61,7 +62,7 @@ namespace IO.Swagger.DTO
/// <summary>
/// Gets or Sets Saisies
/// </summary>
[Required]
[CannotBeEmpty]
[DataMember(Name="saisies")]
public List<SaisieDTO> Saisies { get; set; }

@ -33,12 +33,13 @@ namespace IO.Swagger.DTO
/// <value>Id de la saisie</value>
[Required]
[DataMember(Name="id")]
public string Id { get; set; }
public long? Id { get; set; }
/// <summary>
/// Note saisie
/// </summary>
/// <value>Note saisie</value>
[Required]
[DataMember(Name="note")]
public int? Note { get; set; }
@ -61,7 +62,7 @@ namespace IO.Swagger.DTO
/// </summary>
[Required]
[DataMember(Name="typeSaisie")]
public TypeEp TypeSaisie { get; set; }
public TypeSaisie TypeSaisie { get; set; }
/// <summary>
/// Returns the string presentation of the object

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Exceptions
{
/// <summary>
/// Exception qui est levée lorsque l'id de la participation à une formation avec les données à mettre à jour et l'id de la participation à une formation dans la base de données sont différents
/// </summary>
public class ParticipationFormationIncompatibleIdException : Exception
{
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationIncompatibleIdException"/> class.
/// </summary>
public ParticipationFormationIncompatibleIdException()
{
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationIncompatibleIdException"/> class.
/// </summary>
/// <param name="message"></param>
public ParticipationFormationIncompatibleIdException(string message) : base(message)
{
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationIncompatibleIdException"/> class.
/// </summary>
/// <param name="message"></param>
/// <param name="inner"></param>
public ParticipationFormationIncompatibleIdException(string message, Exception inner) : base(message, inner)
{
}
}
}

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Exceptions
{
/// <summary>
/// Exception qui est levée lorsqu'une participation formation est invalide
/// </summary>
public class ParticipationFormationInvalidException : Exception
{
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationInvalidException"/> class.
/// </summary>
public ParticipationFormationInvalidException()
{
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationInvalidException"/> class.
/// </summary>
/// <param name="message"></param>
public ParticipationFormationInvalidException(string message) : base(message)
{
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationInvalidException"/> class.
/// </summary>
/// <param name="message"></param>
/// <param name="inner"></param>
public ParticipationFormationInvalidException(string message, Exception inner) : base(message, inner)
{
}
}
}

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Exceptions
{
/// <summary>
/// Exception qui est levée lorsqu'une participation à une formation n'a pas été trouvée
/// </summary>
public class ParticipationFormationNotFoundException : Exception
{
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationNotFoundException"/> class.
/// </summary>
public ParticipationFormationNotFoundException()
{
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationNotFoundException"/> class.
/// </summary>
/// <param name="message"></param>
public ParticipationFormationNotFoundException(string message) : base(message)
{
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ParticipationFormationNotFoundException"/> class.
/// </summary>
/// <param name="message"></param>
/// <param name="inner"></param>
public ParticipationFormationNotFoundException(string message, Exception inner) : base(message, inner)
{
}
}
}

@ -0,0 +1,17 @@
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 IParticipationFormationService
{
Task<EvaluationDTO> GetEvaluationCollaborateurAsync(long idParticipationFormation);
Task<IEnumerable<ParticipationFormationDTO>> GetParticipationByCollaborateurAsync(Guid idCollaborateur);
Task<EvaluationDTO> EvaluerFormationAsync(long idParticipationFormation, EvaluationDTO evaluationDTO);
}
}

@ -26,11 +26,6 @@ namespace EPAServeur.Models.Formation
/// </summary>
public bool EstEvaluee { get; set; }
/// <summary>
/// Id de la demande de formation
/// </summary>
public long IdDemandeFormation { get; set; }
/// <summary>
/// Demande de formation qui est lié à la participation d’un collaborateur à une formation
/// </summary>

@ -34,7 +34,7 @@ namespace EPAServeur.Models.SaisieChamp
/// <summary>
/// Ordre du champ dans sa section ou sa sous-section
/// </summary>
public long Ordre { get; set; }
public int Ordre { get; set; }
/// <summary>
/// Type du champ correspondant au Type du document si c’est un champ un EP ou à l’évaluation sinon

@ -0,0 +1,370 @@
using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.IServices;
using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using EPAServeur.Models.SaisieChamp;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Services
{
public class ParticipationFormationService : IParticipationFormationService
{
#region Variables
/// <summary>
/// Accès et gestion de la base de données
/// </summary>
private readonly EpContext epContext;
/// <summary>
/// Accès et service collaborateur
/// </summary>
private readonly ICollaborateurService collaborateurService;
#endregion
#region Contructeurs
/// <summary>
/// Constructeur de la classe FormationService
/// </summary>
/// <param name="_epContext"></param>
public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService)
{
epContext = _epContext;
collaborateurService = _collaborateurService;
}
#endregion
#region Méthodes Service
/// <summary>
/// Récupérer une évaluation faite par un collaborateur.
/// </summary>
/// <param name="idParticipationFormation">Id d&#x27;une participation formation</param>
/// <returns></returns>
public async Task<EvaluationDTO> GetEvaluationCollaborateurAsync(long idParticipationFormation)
{
ParticipationFormation participationFormation;
participationFormation = await epContext.ParticipationFormation
.Include(participationFormation => participationFormation.Evaluation)
.Include(participationFormation => participationFormation.Formation)
.FirstOrDefaultAsync(participationFormation => participationFormation.IdParticipationFormation == idParticipationFormation);
if (participationFormation == null)
throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation));
return GetEvaluationDTO(participationFormation);
}
/// <summary>
/// Récupérer la liste des participations de formation d’un collaborateur.
/// </summary>
/// <param name="idCollaborateur">Id du collaborateur</param>
/// <returns></returns>
public async Task<IEnumerable<ParticipationFormationDTO>> GetParticipationByCollaborateurAsync(Guid idCollaborateur)
{
IQueryable<ParticipationFormation> query;
IEnumerable<ParticipationFormation> participationFormations;
IEnumerable<ParticipationFormationDTO> participationFormationDTOs;
query = epContext.ParticipationFormation
.Include(participationFormation => participationFormation.Evaluation)
.Include(participationFormation => participationFormation.Formation)
.ThenInclude(formation => formation.Statut)
.Include(participationFormation => participationFormation.DemandeFormation)
.ThenInclude(demandeFormation => demandeFormation.Ep)
.Where(participationFormation => participationFormation.DemandeFormation.Ep.IdCollaborateur == idCollaborateur && participationFormation.DemandeFormation.Etat == EtatDemande.Validee);
participationFormations = await query.ToListAsync();
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(participationFormations);
participationFormationDTOs = participationFormations.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs));
return participationFormationDTOs;
}
/// <summary>
/// Evaluer une formation.
/// </summary>
/// <param name="idParticipationFormation">Id d&#x27;une participation formation</param>
/// <param name="evaluationDTO">Evaluation d'une formation</param>
/// <returns></returns>
public async Task<EvaluationDTO> EvaluerFormationAsync(long idParticipationFormation, EvaluationDTO evaluationDTO)
{
ParticipationFormation participationFormation;
if (!evaluationDTO.Id.HasValue || evaluationDTO.Id.Value != idParticipationFormation)
throw new ParticipationFormationIncompatibleIdException("L'id de la participation formation a mettre à jour et la participation formation a mettre à jour sont incompatble.");
IsEvaluationValide(evaluationDTO);
participationFormation = await epContext.ParticipationFormation.Include(p => p.Evaluation)
.FirstOrDefaultAsync(p => p.IdParticipationFormation == idParticipationFormation);
if (participationFormation == null)
throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation));
participationFormation.Evaluation = evaluationDTO.Saisies.Select(s => GetSaisie(s)).ToList();
participationFormation.EstEvaluee = true;
await epContext.SaveChangesAsync();
return GetEvaluationDTO(participationFormation);
}
#endregion
#region Méthodes Privée
/// <summary>
/// Vérifier si un objet EvaluationDTO est valide pour une mise à jour
/// </summary>
/// <remarks>
/// Un objet EvaluationDTO est valide si l'objet n'est pas null, si l'intitulé, la date de début et la valeur permettant de dire si la formation est certifiée ou non ne sont pas null,
/// si l'évaluation possède au moins une saisie et si la saisie a une note
/// </remarks>
/// <param name="evaluation"></param>
/// <returns>true si l'objet est valide, false sinon</returns>
private void IsEvaluationValide(EvaluationDTO evaluation)
{
// Vérifier que l'évaluation n'est pas null
if (evaluation == null)
throw new ParticipationFormationInvalidException("Aucune évaluation n'a été reçue.");
// Vérifier que la formation a bien un intitulé
if (string.IsNullOrWhiteSpace(evaluation.Intitule))
throw new ParticipationFormationInvalidException("L'intitulé de la formation doit contenir au moins 1 caractère.");
// Vérifier que la formation a bien une valeur permettant de dire si la formation est certifiée ou non
if (!evaluation.EstCertifie.HasValue)
throw new ParticipationFormationInvalidException("Impossible d'évaluer une formation sans savoir si la formation est certfiée ou non.");
// Vérifier que la formation a bien une date de début
if (!evaluation.DateDebut.HasValue)
throw new ParticipationFormationInvalidException("Impossible d'évaluer une formation sans date de début de formation.");
// Vérifier que l'évaluation possède au moins une saisie
if (evaluation.Saisies == null || evaluation.Saisies.Count == 0)
throw new ParticipationFormationInvalidException("Impossible d'évaluer une formation sans saisie.");
// Vérifier que l'évaluation possède une note pour chaque saisie
if (evaluation.Saisies.Any(s => !s.Note.HasValue))
throw new ParticipationFormationInvalidException("Toutes les saisies doivent posséder une note.");
}
#region Object to DTO
/// <summary>
/// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO()
{
Id = participationFormation.IdParticipationFormation,
DateCreation = participationFormation.DateCreation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
Statut = GetStatutFormationDTO(participationFormation.Formation.Statut),
Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs),
Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs)
};
return participationFormationDTO;
}
/// <summary>
/// Récuperer un objet EvaluationDTO en fonction d'un objet ParticipationFormation
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation)
{
EvaluationDTO evaluationDTO = new EvaluationDTO()
{
Id = participationFormation.IdParticipationFormation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
EstCertifie = participationFormation.Formation.EstCertifiee,
Saisies = participationFormation.Evaluation.Select(s => GetSaisieDTO(s)).ToList()
};
return evaluationDTO;
}
/// <summary>
/// Récuperer un objet SaisieDTO en fonction d'un objet Saisie
/// </summary>
/// <param name="saisie"></param>
/// <returns></returns>
private SaisieDTO GetSaisieDTO(Saisie saisie)
{
if (saisie == null)
return null;
SaisieDTO saisieDTO = new SaisieDTO()
{
Id = saisie.IdSaisie,
Note = saisie.Note,
Texte = saisie.Texte,
Champ = GetChampDTO(saisie.Champ),
TypeSaisie = saisie.TypeSaisie
};
return saisieDTO;
}
/// <summary>
/// Récuperer un objet ChampDTO en fonction d'un objet Champ
/// </summary>
/// <param name="champ"></param>
/// <returns></returns>
private ChampDTO GetChampDTO(Champ champ)
{
if (champ == null)
return null;
ChampDTO champDTO = new ChampDTO()
{
Id = champ.IdChamp,
Texte = champ.Texte,
Section = champ.Section,
Soussection = champ.SousSection,
Ordre = champ.Ordre,
TypeChamp = champ.TypeChamp,
TypeSaisie = champ.TypeSaisie
};
return champDTO;
}
/// <summary>
/// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation
/// </summary>
/// <param name="statutFormation"></param>
/// <returns></returns>
private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
{
if (statutFormation == null)
return null;
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
{
Id = statutFormation.IdStatutFormation,
Libelle = statutFormation.Libelle
};
return statutFormationDTO;
}
/// <summary>
/// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation.
/// </summary>
/// <param name="participationsFormation"></param>
/// <returns></returns>
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(IEnumerable<ParticipationFormation> participationsFormation)
{
if (!participationsFormation.Any())
return null;
List<Guid?> guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList();
return await collaborateurService.GetCollaborateurDTOsAsync(guids); ;
}
/// <summary>
/// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur);
}
/// <summary>
/// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="ep"></param>
/// <returns></returns>
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
CollaborateurDTO collaborateur;
CollaborateurDTO referent;
collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur);
referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent);
EpInformationDTO epInformationDTO = new EpInformationDTO()
{
Id = ep.IdEP,
Type = ep.TypeEP,
Statut = ep.Statut,
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Collaborateur = collaborateur,
Referent = referent,
};
return epInformationDTO;
}
#endregion
#region DTO to Object
/// <summary>
/// Récuperer un objet Saisie en fonction d'un objet SaisieDTO
/// </summary>
/// <param name="saisieDTO"></param>
/// <returns></returns>
private Saisie GetSaisie(SaisieDTO saisieDTO)
{
Saisie saisie = new Saisie()
{
IdSaisie = saisieDTO.Id.Value,
Note = saisieDTO.Note,
Texte = saisieDTO.Texte,
Champ = GetChamp(saisieDTO.Champ),
TypeSaisie = saisieDTO.TypeSaisie
};
return saisie;
}
/// <summary>
/// Récuperer un objet Champ en fonction d'un objet ChampDTO
/// </summary>
/// <param name="champDTO"></param>
/// <returns></returns>
private Champ GetChamp(ChampDTO champDTO)
{
Champ champ = new Champ()
{
IdChamp = champDTO.Id.Value,
Texte = champDTO.Texte,
Section = champDTO.Section,
SousSection = champDTO.Soussection,
Ordre = champDTO.Ordre.Value,
TypeChamp = champDTO.TypeChamp,
TypeSaisie = champDTO.TypeSaisie
};
return champ;
}
#endregion
#endregion
}
}

@ -125,6 +125,7 @@ namespace EPAServeur
services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IEpInformationService, EpInformationService>();
services.AddScoped<IFormationService, FormationService>();
services.AddScoped<IParticipationFormationService, ParticipationFormationService>();
services.AddScoped<INoteService, NoteService>();
services.AddScoped<IReferentEPService, ReferentEPService>();
services.AddScoped<IEngagementService, EngagementService>();

Loading…
Cancel
Save