diff --git a/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs b/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs index 136459e..8506e9e 100644 --- a/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs +++ b/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs @@ -25,6 +25,7 @@ namespace EPAServeur.Tests.Controllers IDemandeDelegationService demandeDelegationService; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; #endregion #region Setup @@ -55,8 +56,9 @@ namespace EPAServeur.Tests.Controllers } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); - demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); } #endregion diff --git a/EPAServeur.Tests/Controllers/EngagementsApiTests.cs b/EPAServeur.Tests/Controllers/EngagementsApiTests.cs index ca0501b..815ab8a 100644 --- a/EPAServeur.Tests/Controllers/EngagementsApiTests.cs +++ b/EPAServeur.Tests/Controllers/EngagementsApiTests.cs @@ -64,6 +64,7 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/EPAServeur.Tests/Controllers/EpInformationApiTests.cs b/EPAServeur.Tests/Controllers/EpInformationApiTests.cs index 97acaf0..023def8 100644 --- a/EPAServeur.Tests/Controllers/EpInformationApiTests.cs +++ b/EPAServeur.Tests/Controllers/EpInformationApiTests.cs @@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Controllers private ICollaborateurService collaborateurService; private IEpInformationService epInformationService; private ILogger logger; + private ITransformDTO transformDTO; #endregion @@ -50,8 +51,9 @@ namespace EPAServeur.Tests.Controllers { entity.State = EntityState.Detached; } - collaborateurService = new CollaborateurService(new CollaborateurApi(), context); - epInformationService = new EpInformationService(context, collaborateurService); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO); + epInformationService = new EpInformationService(context, collaborateurService, transformDTO); } #endregion diff --git a/EPAServeur.Tests/Controllers/FormationApiTests.cs b/EPAServeur.Tests/Controllers/FormationApiTests.cs index aff0d95..c31d43e 100644 --- a/EPAServeur.Tests/Controllers/FormationApiTests.cs +++ b/EPAServeur.Tests/Controllers/FormationApiTests.cs @@ -63,6 +63,7 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/EPAServeur.Tests/Controllers/NoteApiTests.cs b/EPAServeur.Tests/Controllers/NoteApiTests.cs index a4e5e36..b53cee7 100644 --- a/EPAServeur.Tests/Controllers/NoteApiTests.cs +++ b/EPAServeur.Tests/Controllers/NoteApiTests.cs @@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Controllers private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; private INoteService noteService; private ILogger logger; private Guid? auteur1, collaborateur1; @@ -53,8 +54,10 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); - noteService = new NoteService(collaborateurApi, collaborateurService, context); + + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); logger = new NullLogger(); auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); diff --git a/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs b/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs index 1f8da96..1527906 100644 --- a/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs +++ b/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs @@ -65,6 +65,7 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs b/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs index 4f789a5..2d9bdf8 100644 --- a/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs +++ b/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs @@ -21,6 +21,7 @@ namespace EPAServeur.Tests.Controllers #region Variables private EpContext context; private ICollaborateurApi collaborateurApi; + private ITransformDTO transformDTO; private IReferentEPService referentEPService; private Guid? referent, collaborateur1, collaborateur2, collaborateur3; #endregion diff --git a/EPAServeur.Tests/Services/CollaborateurServiceTests.cs b/EPAServeur.Tests/Services/CollaborateurServiceTests.cs index f8ac6ef..b415585 100644 --- a/EPAServeur.Tests/Services/CollaborateurServiceTests.cs +++ b/EPAServeur.Tests/Services/CollaborateurServiceTests.cs @@ -20,6 +20,8 @@ namespace EPAServeur.Tests.Services #region private EpContext context; private ICollaborateurApi collaborateurApi; + private ITransformDTO transformDTO; + #endregion #region Setup @@ -46,6 +48,7 @@ namespace EPAServeur.Tests.Services { entity.State = EntityState.Detached; } + transformDTO = new TransformDTO(); collaborateurApi = new CollaborateurApi(); } #endregion @@ -57,7 +60,8 @@ namespace EPAServeur.Tests.Services [TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")] public async Task GetCollaborateurById_Ok(Guid? id) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(id); Assert.IsNotNull(collaborateurDTO); @@ -69,7 +73,8 @@ namespace EPAServeur.Tests.Services [TestCase("coty.lemoine@apside-groupe.com")] public async Task GetCollaborateurByMail_Ok(string mail) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByMailAsync(mail); Assert.IsNotNull(collaborateurDTO); @@ -79,10 +84,10 @@ namespace EPAServeur.Tests.Services [TestCase("006226f6-51b2-4a02-a302-7447f7fccc04")] [TestCase("e5d36da4-df16-4d19-8a11-1ba2f6efc80c")] [TestCase("92b29b9c-40a4-4aa0-9412-bc97a379e52f")] - public async Task GetCollaborateurById_CollaborateurNotFound(Guid? id) + public void GetCollaborateurById_CollaborateurNotFound(Guid? id) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); - + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByIdAsync(id); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); } @@ -90,9 +95,10 @@ namespace EPAServeur.Tests.Services [TestCase("nicolas@apside.fr")] [TestCase("rousseau@apside.fr")] [TestCase("lemoine@apside.fr")] - public async Task GetCollaborateurByMail_CollaborateurNotFound(string mail) + public void GetCollaborateurByMail_CollaborateurNotFound(string mail) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByMailAsync(mail); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); } @@ -108,7 +114,7 @@ namespace EPAServeur.Tests.Services [TestCase("RA")] public async Task GetCollaborateurs_UnRole(string role) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); List roles = new List(); roles.Add(role); @@ -142,7 +148,7 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurs_RoleRH_RoleAssistant() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); List roles = new List(); roles.Add("Assistant"); @@ -156,7 +162,7 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurs_RoleRA_RoleManager() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); List roles = new List(); roles.Add("Manager"); @@ -175,7 +181,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurs_Asc_Desc() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateursAsc = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, null); IEnumerable collaborateursDesc = await collaborateurService.GetCollaborateursAsync(null, null, false, 1, 50, "", "", null, null); CollaborateurDTO collaborateurDTOFirstAsc = collaborateursAsc.First(); @@ -193,7 +200,8 @@ namespace EPAServeur.Tests.Services [TestCase("")] public async Task GetCollaborateurs_Texte(string texte) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, texte, "", null, null); string nomprenom, prenomnom; foreach(CollaborateurDTO collaborateur in collaborateurs) @@ -210,7 +218,8 @@ namespace EPAServeur.Tests.Services [TestCase(2018,1,1)] public async Task GetCollaborateurs_DateDebut(int annee, int mois, int jour) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + DateTime dateDebut = new DateTime(annee, mois, jour); IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, null); foreach(CollaborateurDTO collaborateur in collaborateurs) @@ -225,7 +234,8 @@ namespace EPAServeur.Tests.Services [TestCase(2017, 12, 31)] public async Task GetCollaborateurs_DateFin(int annee, int mois, int jour) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + DateTime dateFin = new DateTime(annee, mois, jour); IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, dateFin); foreach (CollaborateurDTO collaborateur in collaborateurs) @@ -240,8 +250,9 @@ namespace EPAServeur.Tests.Services [TestCase(2019,1,1,2019,12,31)] public async Task GetCollaborateurs_DateDebutDateFin(int anneeDeb, int moisDeb, int jourDeb, int anneeFin, int moisFin, int jourFin) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); - DateTime dateDebut= new DateTime(anneeDeb, moisDeb, jourDeb); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + + DateTime dateDebut = new DateTime(anneeDeb, moisDeb, jourDeb); DateTime dateFin = new DateTime(anneeFin, moisFin, jourFin); IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, dateFin); foreach (CollaborateurDTO collaborateur in collaborateurs) @@ -259,7 +270,8 @@ namespace EPAServeur.Tests.Services [TestCase(1,37)] public async Task GetCollaborateur_Paginaion(int numPage, int parPage) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); Assert.AreEqual(collaborateurs.Count(), parPage); } @@ -269,7 +281,8 @@ namespace EPAServeur.Tests.Services [TestCase(8, 5, 2)] public async Task GetCollaborateur_Paginaion_2(int numPage, int parPage, int res) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); Assert.AreEqual(collaborateurs.Count(), res); } @@ -281,7 +294,8 @@ namespace EPAServeur.Tests.Services [TestCase(-1, 37)] public async Task GetCollaborateur_PaginaionValeursParDefaut(int numPage, int parPage) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); if(parPage < 5) @@ -294,7 +308,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateur_OrderByDateArrive() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "datearrivee", null, null); DateTime d1, d2; for(int i = 0; i < collaborateurs.Count() -1; ++i) @@ -310,7 +325,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateur_OrderByBU() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "businessunit", null, null); string bu1, bu2; for (int i = 0; i < collaborateurs.Count() - 1; ++i) @@ -327,7 +343,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateur_OrderByNom() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "collaborateur", null, null); string nom1, nom2; for (int i = 0; i < collaborateurs.Count() - 1; ++i) @@ -348,7 +365,8 @@ namespace EPAServeur.Tests.Services [TestCase("642bc07f-051a-4088-8a73-425b44998673")] public async Task GetCollaborateurByReferentPlusCount(Guid idReferent) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", ""); int count = await collaborateurService.GetCollaborateursCountByReferentAsync(idReferent, ""); Assert.AreEqual(count, collaborateurs.Count()); @@ -361,7 +379,8 @@ namespace EPAServeur.Tests.Services [TestCase("ca1f480a-9918-4cea-819c-62e5c7f2b332")] public void GetCollaborateurByReferent_ReferentNotFound(Guid idReferent) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + AsyncTestDelegate exception = () => collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", ""); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); } @@ -375,7 +394,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurByGuids() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + List guids = new List(); guids.Add(new Guid("ebd911ef-a6a8-4047-afdc-9a9066aa1a07")); guids.Add(new Guid("71d33f6d-695a-4dc6-ae1a-b1605fd2073d")); @@ -394,7 +414,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurByGuidsAvecIdsNonExistantEnPlus() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + List guids = new List(); guids.Add(new Guid("b645f582-0a5d-48dc-97a1-4ebb0fb3a29f")); guids.Add(new Guid()); @@ -414,7 +435,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurByGuidsAvecIdsNonExistantUniquement() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + List guids = new List(); guids.Add(new Guid()); guids.Add(new Guid()); diff --git a/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs b/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs index 36dd8d4..e26fc6e 100644 --- a/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs +++ b/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs @@ -23,6 +23,8 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; + #endregion #region Setup @@ -52,7 +54,8 @@ namespace EPAServeur.Tests.Services entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); } #endregion @@ -65,7 +68,7 @@ namespace EPAServeur.Tests.Services [TestCase("17b87130-0e9d-4b78-b0e3-a11e5f70318d", 1)] public async Task RecupererDemandesDelegation_OK(Guid? idReferent, int count) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); IEnumerable demandesDelegation = await demandeDelegationService.RecupererDemandesDelegation(idReferent); foreach (DemandeDelegationDTO demandeDelegation in demandesDelegation) { @@ -80,7 +83,7 @@ namespace EPAServeur.Tests.Services public void RecupererDemandeDelegation_ReferentNotFound() { Guid? idReferent = new Guid(); - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => demandeDelegationService.RecupererDemandesDelegation(idReferent); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); } @@ -93,7 +96,7 @@ namespace EPAServeur.Tests.Services [TestCase(5)] public async Task UpdateDemandeDelegation_ReponsePositive(long id) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id); long idEp = demandeDelegation.IdEP; @@ -125,7 +128,7 @@ namespace EPAServeur.Tests.Services [TestCase(6)] public async Task UpdateDemandeDelegation_ReponseNegative(long id) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id); long idEp = demandeDelegation.IdEP; @@ -156,7 +159,7 @@ namespace EPAServeur.Tests.Services [TestCase(10, EtatDemande.Rejetee, "exemple refus")] public void UpdateDemandeDelegation_DemandeNonExistante(long id, EtatDemande etatDemande, string raisonRefus) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() { Id = id, @@ -176,7 +179,7 @@ namespace EPAServeur.Tests.Services [TestCase(4, 1,EtatDemande.Rejetee, "exemple refus")] public void UpdateDemandeDelegation_DemandeIncompatible(long id, long idIncompatible, EtatDemande etatDemande, string raisonRefus) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() { Id = id, @@ -199,7 +202,7 @@ namespace EPAServeur.Tests.Services [TestCase(7, EtatDemande.Rejetee, "")] public async Task UpdateDemandeDelegation_DemandeInvalid(long id, EtatDemande etatDemande, string raisonRefus) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id); long idEp = demandeDelegation.IdEP; diff --git a/EPAServeur.Tests/Services/EngagementServiceTests.cs b/EPAServeur.Tests/Services/EngagementServiceTests.cs index 5ab7833..da06403 100644 --- a/EPAServeur.Tests/Services/EngagementServiceTests.cs +++ b/EPAServeur.Tests/Services/EngagementServiceTests.cs @@ -23,6 +23,8 @@ namespace EPAServeur.Tests.Services private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; + #endregion #region Setup @@ -37,7 +39,8 @@ namespace EPAServeur.Tests.Services epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, epContext); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); @@ -61,7 +64,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseDesParamsDesIdBUValides_RetourneDesEngagements(long[] arrIdBUs) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = arrIdBUs.Select(x => x).ToList(); // Act @@ -76,7 +79,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseDesParamsDesEtatsDEngagementsValides_RetourneDesEngagements(EtatEngagement[] arrEtatsEngagement) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; List etatEngagements = arrEtatsEngagement.Select(x => x).ToList(); @@ -92,7 +95,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesEngagements(int? numPage, int? parPage) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; // Act @@ -109,7 +112,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPage) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; int? nbEngagementDeuxiemePage; @@ -142,7 +145,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionCroissant(bool? asc, string tri) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; // Act @@ -159,7 +162,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionDecroissant(bool? asc, string tri) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; // Act @@ -174,7 +177,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifCroissant() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = true; string tri = "dispositif"; @@ -191,7 +194,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifDecroissant() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = false; string tri = "dispositif"; @@ -208,7 +211,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteCroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = true; string tri = "modalite"; @@ -225,7 +228,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteDecroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = false; string tri = "modalite"; @@ -242,7 +245,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateCroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = true; string tri = "date"; @@ -259,7 +262,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateDecroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = false; string tri = "date"; @@ -279,7 +282,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseDesParamsInvalides_RetourneZeroEngagement(long[] arrIdBUs, string texte) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs; if (arrIdBUs != null) @@ -298,7 +301,7 @@ namespace EPAServeur.Tests.Services public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUVide_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List(); // Act @@ -312,7 +315,7 @@ namespace EPAServeur.Tests.Services public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUNull_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = null; // Act @@ -332,7 +335,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDEngagements(long[] arrIdBUs, string texte) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs; if (arrIdBUs != null) @@ -353,7 +356,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsCountAsync_PasseDesParamsInvalides_RetourneZero(long[] arrIdBUs, string texte) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs; if (arrIdBUs != null) @@ -378,7 +381,7 @@ namespace EPAServeur.Tests.Services public async Task RepondreEngagementAsync_ModifieUnEngagementValide_EngagementModifieAvecSucces(long idEngagement, long idEp, EtatEngagement etatEngagement, string raisonNonRealisable) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -423,7 +426,7 @@ namespace EPAServeur.Tests.Services string raisonNonRealisableAvantUpdate = null; string raisonNonRealisableApresUpdate = "La date limite pour respecter l'engagement est passée."; // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -469,7 +472,7 @@ namespace EPAServeur.Tests.Services public void RepondreEngagementAsync_ModifieUnEngagementAvecDesProprietesInvalide_LeveUneEngagementInvalidException(long idEngagement, long idEp, string action, string dispositif, string modalite, DateTime? dateLimite, EtatEngagement etatEngagement, string raisonNonRealisable) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -505,7 +508,7 @@ namespace EPAServeur.Tests.Services public void RepondreEngagementAsync_ModifieUnEngagementNull_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EngagementDTO engagementDTO = null; long idEngagement = 1; @@ -520,7 +523,7 @@ namespace EPAServeur.Tests.Services public void RepondreEngagementAsync_ModifieUnEngagementAvecUnEPInexistantDansLaBDD_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); long idEngagement = 1; EpInformationDTO epInformationDTO = new EpInformationDTO { @@ -561,7 +564,7 @@ namespace EPAServeur.Tests.Services long idEngagementIncorrecte = 2; long idEp = 9; - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -600,7 +603,7 @@ namespace EPAServeur.Tests.Services long idEngagement = 0; long idEp = 9; - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO diff --git a/EPAServeur.Tests/Services/EpInformationTests.cs b/EPAServeur.Tests/Services/EpInformationTests.cs index b1fe14f..a67f9a1 100644 --- a/EPAServeur.Tests/Services/EpInformationTests.cs +++ b/EPAServeur.Tests/Services/EpInformationTests.cs @@ -20,6 +20,8 @@ namespace EPAServeur.Tests.Services #region private EpContext context; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; + #endregion @@ -47,7 +49,8 @@ namespace EPAServeur.Tests.Services { entity.State = EntityState.Detached; } - collaborateurService = new CollaborateurService(new CollaborateurApi(), context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO); } #endregion @@ -58,7 +61,7 @@ namespace EPAServeur.Tests.Services [TestCase(3, 3)] // Paris public async Task GetEpEnCours_UneBU(long? idBUs, int nbElements) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List{ idBUs }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPEnCoursCount(new List { idBUs }, true, 1, 15, "", "", null, null); @@ -74,7 +77,7 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetEpEnCours_OrleansTours() { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1,2 }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPEnCoursCount(new List { 1, 2 }, true, 1, 15, "", "", null, null); @@ -100,7 +103,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpEnCours_TriColonneASC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -153,7 +156,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpEnCours_TriColonneDESC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, false, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -201,7 +204,7 @@ namespace EPAServeur.Tests.Services public async Task GetEpEnCours_TriDateD1(int j, int m, int a, int count) { DateTime date = new DateTime(a, m, j); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", "", date, null); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -217,7 +220,7 @@ namespace EPAServeur.Tests.Services [TestCase(1, 02, 2021, 0)] public async Task GetEpEnCours_TriDateD2(int j, int m, int a, int count) { - DateTime date = new DateTime(a, m, j); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + DateTime date = new DateTime(a, m, j); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", "", null, date); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -237,7 +240,7 @@ namespace EPAServeur.Tests.Services { DateTime date1 = new DateTime(a1, m1, j1); DateTime date2 = new DateTime(a2, m2, j2); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", "", date1, date2); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -259,7 +262,7 @@ namespace EPAServeur.Tests.Services [TestCase("d", 2)] public async Task GetEpEnCours_texte(string texte, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, texte, "", null, null); Assert.AreEqual(count, epInformationDTOs.Count()); foreach (EpInformationDTO ep in epInformationDTOs) @@ -279,7 +282,7 @@ namespace EPAServeur.Tests.Services [TestCase(3, 3)] // Paris public async Task GetEpSignes_UneBU(long? idBUs, int nbElements) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List{ idBUs }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPSignesCount(new List { idBUs }, true, 1, 15, "", "", null, null); @@ -295,7 +298,7 @@ namespace EPAServeur.Tests.Services public async Task GetEpSignes_OrleansTours() { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1,2 }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPSignesCount(new List { 1, 2 }, true, 1, 15, "", "", null, null); @@ -321,7 +324,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpSignes_TriColonneASC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -375,7 +378,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpSignes_TriColonneDESC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, false, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -426,7 +429,7 @@ namespace EPAServeur.Tests.Services public async Task GetEpSignes_TriDateD1(int j, int m, int a, int count) { DateTime date = new DateTime(a, m, j); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", "", date, null); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -443,7 +446,7 @@ namespace EPAServeur.Tests.Services [TestCase(31, 07, 2017)] public async Task GetEpSignes_TriDateD2(int j, int m, int a) { - DateTime date = new DateTime(a, m, j); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + DateTime date = new DateTime(a, m, j); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", "", null, date); int count = await epInformationService.GetEPSignesCount(new List { 1, 2 }, true, 1, 15, "", "", null, date); @@ -463,7 +466,7 @@ namespace EPAServeur.Tests.Services { DateTime date1 = new DateTime(a1, m1, j1); DateTime date2 = new DateTime(a2, m2, j2); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", "", date1, date2); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -485,7 +488,7 @@ namespace EPAServeur.Tests.Services [TestCase("d", 2)] public async Task GetEpSignes_texte(string texte, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, texte, "", null, null); Assert.AreEqual(count, epInformationDTOs.Count()); foreach (EpInformationDTO ep in epInformationDTOs) @@ -508,7 +511,7 @@ namespace EPAServeur.Tests.Services [TestCase("80220063-a5fa-472b-b610-2e350566df98", 1)] public async Task GetEPCoursReferent(Guid idReferent, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCoursReferent(idReferent, true, 1, 15, "", "", null, null); int epCount = await epInformationService.GetEPEnCoursReferentCount(idReferent, true, 1, 15, "", "", null, null); Assert.AreEqual(epCount, count); @@ -531,7 +534,7 @@ namespace EPAServeur.Tests.Services [TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)] public async Task GetEPEnSignesReferent(Guid idReferent, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignesReferent(idReferent, true, 1, 15, "", "", null, null); int epCount = await epInformationService.GetEPSignesReferentCount(idReferent, true, 1, 15, "", "", null, null); Assert.AreEqual(epCount, count); @@ -553,7 +556,7 @@ namespace EPAServeur.Tests.Services [TestCase("13fbe621-1bc9-4f04-afde-b54ca076e239", 3)] public async Task GetEPSignesCollaborateur(Guid idCollaborateur, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignesCollaborateur(idCollaborateur); Assert.AreEqual(count, epInformationDTOs.Count()); foreach(EpInformationDTO ep in epInformationDTOs) @@ -574,7 +577,7 @@ namespace EPAServeur.Tests.Services [TestCase("de98a866-736f-4295-a669-92a8694e2ee3", true)] public async Task GetEPEnCoursCollaborateur(Guid idCollaborateur, bool existe) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = await epInformationService.GetProchainEPCollaborateur(idCollaborateur); if(existe) { diff --git a/EPAServeur.Tests/Services/FormationServiceTests.cs b/EPAServeur.Tests/Services/FormationServiceTests.cs index 5c16163..fddaf76 100644 --- a/EPAServeur.Tests/Services/FormationServiceTests.cs +++ b/EPAServeur.Tests/Services/FormationServiceTests.cs @@ -22,6 +22,7 @@ namespace EPAServeur.Tests.Services private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; #endregion #region Setup @@ -36,7 +37,8 @@ namespace EPAServeur.Tests.Services epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, epContext); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); @@ -59,7 +61,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act FormationDTO formationDTO = await formationService.GetFormationByIdAsync(3); @@ -85,7 +87,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormationSansParticipation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); long idFormation = 11; // Act @@ -114,7 +116,7 @@ namespace EPAServeur.Tests.Services public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long idFormation) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(idFormation); @@ -136,7 +138,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseDesParamsValides_RetourneDesFormations(long? idAgence, int[] arrIdStatuts, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -156,7 +158,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesFormations(int? numPage, int? parPAge) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, numPage, parPAge, null, null, null, null); @@ -172,7 +174,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPAge) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); int? nbFormationDeuxiemePage; switch (parPAge) @@ -204,7 +206,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleCroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -221,7 +223,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleDecroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -236,7 +238,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutCroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -251,7 +253,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutDecroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -266,7 +268,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsCroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -281,7 +283,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsDecroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -296,7 +298,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineCroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -311,7 +313,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineDecroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -326,7 +328,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateCroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -341,7 +343,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateDecroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -356,7 +358,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationCroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -371,7 +373,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationDecroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -387,7 +389,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeDebut_RetourneDesFormationsAvecUneDateDeDebutSuperieur(DateTime dateDebut) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, null); @@ -402,7 +404,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeFin_RetourneDesFormationsAvecUneDateDeFinInferieur(DateTime dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, null, dateFin); @@ -417,7 +419,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutEtUneDateDeFin_RetourneDesFormationsAvecUneDateDeDebutSuperieurUneDateDeFinInferieur(DateTime dateDebut, DateTime dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); @@ -435,7 +437,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutSuperieurEtUneDateDeFinInferieur_RetourneZeroFormation(DateTime dateDebut, DateTime dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); @@ -450,7 +452,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(long? idAgence, int[] arrIdStatuts, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -479,7 +481,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeFormations(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -500,7 +502,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsCountAsync_PasseDesParamsInvalides_RetourneZero(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -524,7 +526,7 @@ namespace EPAServeur.Tests.Services public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable modeFormationDTOs = await formationService.GetModesFormationAsync(); @@ -542,7 +544,7 @@ namespace EPAServeur.Tests.Services public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable origineFormationDTOs = await formationService.GetOriginesFormationAsync(); @@ -560,7 +562,7 @@ namespace EPAServeur.Tests.Services public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable statutFormationDTOs = await formationService.GetStatutsFormationAsync(); @@ -578,7 +580,7 @@ namespace EPAServeur.Tests.Services public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable typeFormationDTOs = await formationService.GetTypesFormationAsync(); @@ -623,7 +625,7 @@ namespace EPAServeur.Tests.Services EstCertifiee = false }; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act FormationDTO formationAjoute = await formationService.AddFormationAsync(formation); @@ -652,7 +654,7 @@ namespace EPAServeur.Tests.Services // Arrange FormationDTO formation = null; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); @@ -701,7 +703,7 @@ namespace EPAServeur.Tests.Services EstCertifiee = false }; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); @@ -747,7 +749,7 @@ namespace EPAServeur.Tests.Services EstCertifiee = false }; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); @@ -773,7 +775,7 @@ namespace EPAServeur.Tests.Services 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); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation); @@ -837,7 +839,7 @@ namespace EPAServeur.Tests.Services 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); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation); @@ -876,7 +878,7 @@ namespace EPAServeur.Tests.Services 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); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = await formationService.GetFormationByIdAsync(1); @@ -914,7 +916,7 @@ namespace EPAServeur.Tests.Services 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); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = new FormationDTO { @@ -950,7 +952,7 @@ namespace EPAServeur.Tests.Services public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long idFormation) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); bool existFormation = true; // Act @@ -967,7 +969,7 @@ namespace EPAServeur.Tests.Services public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long idFormation) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(idFormation); diff --git a/EPAServeur.Tests/Services/NoteServiceTests.cs b/EPAServeur.Tests/Services/NoteServiceTests.cs index e98dbed..c33ca0c 100644 --- a/EPAServeur.Tests/Services/NoteServiceTests.cs +++ b/EPAServeur.Tests/Services/NoteServiceTests.cs @@ -21,6 +21,7 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; private Guid? auteur1, auteur2, auteur3; private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? auteurNonExistant, collaborateurNonExistant, collaborateurParti, referentParti; @@ -51,7 +52,8 @@ namespace EPAServeur.Tests.Services entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); @@ -81,7 +83,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateur2DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2); CollaborateurDTO collaborateur3DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO noteAjoutee1, noteAjoutee2; @@ -203,7 +205,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO noteAjoutee1 = new DetailsNoteDTO() @@ -226,7 +228,7 @@ namespace EPAServeur.Tests.Services { CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO note = new DetailsNoteDTO() @@ -249,7 +251,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); collaborateurDTO.Id = collaborateurNonExistant; - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO note = new DetailsNoteDTO() @@ -274,7 +276,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); CollaborateurDTO collaborateurPartiDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateurParti); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; @@ -317,7 +319,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task GetNote_NoteNotNull(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO detailsNoteDTO = await noteService.GetNoteByIdAsync(id); Assert.NotNull(detailsNoteDTO); @@ -341,7 +343,7 @@ namespace EPAServeur.Tests.Services [TestCase(100)] public void GetNote_NoteNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); } @@ -350,7 +352,7 @@ namespace EPAServeur.Tests.Services [TestCase(7)] public void GetNote_ReferentNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); } @@ -359,7 +361,7 @@ namespace EPAServeur.Tests.Services [TestCase(10)] public void GetNote_CollaborateurNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); } @@ -375,7 +377,7 @@ namespace EPAServeur.Tests.Services [TestCase(8)] public async Task SupprimerNote_Succes(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); await noteService.SupprimerNoteAsync(id); Note note = await context.Note.FindAsync(id); @@ -393,7 +395,7 @@ namespace EPAServeur.Tests.Services [TestCase(100)] public void SupprimerNote_NoteNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.SupprimerNoteAsync(id); Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); @@ -410,7 +412,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_UpdateTitreEtTexte(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; note.Texte= "Texte à jour " + id; @@ -433,7 +435,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_UpdateTexte(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Texte = "Texte à jour " + id; DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note); @@ -455,7 +457,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_UpdateTitre(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note); @@ -479,7 +481,7 @@ namespace EPAServeur.Tests.Services [TestCase(9,7)] public async Task UpdateNote_NoteIdImcompatibleExceptionId(long id, long mauvaisId) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; note.Texte = "Texte à jour " + id; @@ -493,7 +495,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_NoteIdImcompatibleExceptionDate(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; note.Texte = "Texte à jour " + id; diff --git a/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs b/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs index cafddf1..014ffbc 100644 --- a/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs +++ b/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs @@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Services private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; #endregion #region Setup @@ -37,7 +38,8 @@ namespace EPAServeur.Tests.Services epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, epContext); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); @@ -61,7 +63,7 @@ namespace EPAServeur.Tests.Services public async Task GetEvaluationCollaborateurAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneEvaluation() { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; // Act EvaluationDTO evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); @@ -79,7 +81,7 @@ namespace EPAServeur.Tests.Services public void GetEvaluationCollaborateurAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneParticipationFormationNotFoundException(long idParticipationFormation) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); @@ -97,7 +99,7 @@ namespace EPAServeur.Tests.Services public async Task GetParticipationByCollaborateurAsync_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); @@ -111,7 +113,7 @@ namespace EPAServeur.Tests.Services public async Task GetParticipationByCollaborateurAsync_PasseDesParamsInvalides_RetourneZeroParticipation(Guid idCollaborateur) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); @@ -128,7 +130,7 @@ namespace EPAServeur.Tests.Services public async Task EvaluerFormationAsync_EvaluerUneFormationValide_EvaluationRealiseeAvecSucces() { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -198,7 +200,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -259,7 +261,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; bool? estCertifiee = null; @@ -321,7 +323,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; DateTime? dateDebut = null; @@ -383,7 +385,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -411,7 +413,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -439,7 +441,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -498,7 +500,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -558,7 +560,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = null; @@ -574,7 +576,7 @@ namespace EPAServeur.Tests.Services public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecte_LeveUneParticipationFormationIncompatibleIdException(long idParticipationFormationIncompatible) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -634,7 +636,7 @@ namespace EPAServeur.Tests.Services public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecteAuNiveauDuDTO_LeveUneParticipationFormationIncompatibleIdException(long? idParticipationFormationIncompatible) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -695,7 +697,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; long idParticipationFormationInexistant = 0; diff --git a/EPAServeur.Tests/Services/ReferentEPTests.cs b/EPAServeur.Tests/Services/ReferentEPTests.cs index b376aac..7774297 100644 --- a/EPAServeur.Tests/Services/ReferentEPTests.cs +++ b/EPAServeur.Tests/Services/ReferentEPTests.cs @@ -22,6 +22,7 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; private Guid? referent1; private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? collaborateurNonExistant, collaborateurParti; @@ -48,7 +49,8 @@ namespace EPAServeur.Tests.Services entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); referent1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); diff --git a/EPAServeur/IServices/ICollaborateurService.cs b/EPAServeur/IServices/ICollaborateurService.cs index f8c4a65..3681f34 100644 --- a/EPAServeur/IServices/ICollaborateurService.cs +++ b/EPAServeur/IServices/ICollaborateurService.cs @@ -1,4 +1,6 @@ using EPAServeur.Context; +using EPAServeur.Models.EP; +using EPAServeur.Models.Formation; using IO.Swagger.DTO; using IO.Swagger.ModelCollaborateur; using System; @@ -19,7 +21,12 @@ namespace EPAServeur.IServices Task GetCollaborateursCountByReferentAsync(Guid? idReferent, string texte); Task> GetReferentsPrecedentsEPAsync(Guid? idCollaborateur); Task> GetCollaborateurDTOsAsync(List guids); - + Task> GetCollaborateurDTOsAsync(List participationsFormation); + Task> GetCollaborateurDTOsAsync(IEnumerable participationsFormation); + Task> GetCollaborateurDTOsAsync(Engagement engagement); + Task> GetCollaborateurDTOsAsync(IEnumerable engagements); + Task> GetCollaborateurDTOsAsync(IEnumerable eps); + Task GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent); } diff --git a/EPAServeur/IServices/ITransformDTO.cs b/EPAServeur/IServices/ITransformDTO.cs new file mode 100644 index 0000000..2565734 --- /dev/null +++ b/EPAServeur/IServices/ITransformDTO.cs @@ -0,0 +1,59 @@ +using EPAServeur.Models.EP; +using EPAServeur.Models.Formation; +using EPAServeur.Models.Notes; +using EPAServeur.Models.SaisieChamp; +using IO.Swagger.DTO; +using IO.Swagger.ModelCollaborateur; +using System.Collections.Generic; + + +namespace EPAServeur.IServices +{ + public interface ITransformDTO + { + // Collaborateur + AgenceDTO GetAgenceDTO(Agence agence); + BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit); + CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs); + + // DemandeDelegation + DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable collaborateurs); + + // Engagement + EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable collaborateurDTOs); + Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO); + + // EpInformation + EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurs); + EpInformationDTO EpToEpDTO(Ep ep, IEnumerable collaborateurDTOs); + + // Formation + FormationDTO GetFormationDTOWhitoutParticipationFormation(Formation formation); + FormationDTO GetFormationDTO(Formation formation, IEnumerable collaborateurDTOs); + FormationDetailsDTO GetFormationDetailsDTO(Formation formation); + OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation); + StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation); + ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation); + TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation); + Formation SetFormation(Formation formation, FormationDTO formationDTO); + OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO); + StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO); + ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO); + TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO); + + // Note + AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable collaborateurs); + DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur); + Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO); + + // ParticipationFormation + List GetParticipationsFormationDTO(List participationsFormation, IEnumerable collaborateurDTOs); + ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs); + EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation); + SaisieDTO GetSaisieDTO(Saisie saisie); + ChampDTO GetChampDTO(Champ champ); + Saisie GetSaisie(SaisieDTO saisieDTO); + Champ GetChamp(ChampDTO champDTO); + + } +} diff --git a/EPAServeur/Services/CollaborateurService.cs b/EPAServeur/Services/CollaborateurService.cs index 1837b35..942747c 100644 --- a/EPAServeur/Services/CollaborateurService.cs +++ b/EPAServeur/Services/CollaborateurService.cs @@ -2,6 +2,7 @@ using EPAServeur.Exceptions; using EPAServeur.IServices; using EPAServeur.Models.EP; +using EPAServeur.Models.Formation; using IO.Swagger.ApiCollaborateur; using IO.Swagger.DTO; using IO.Swagger.ModelCollaborateur; @@ -26,6 +27,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurApi collaborateurApi; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + /// /// Nombre d'éléments min à afficher par page /// @@ -49,10 +55,11 @@ namespace EPAServeur.Services #region Constructeurs - public CollaborateurService(ICollaborateurApi _collaborateurApi, EpContext _contexte) + public CollaborateurService(ICollaborateurApi _collaborateurApi, EpContext _contexte, ITransformDTO _transformDTO) { collaborateurApi = _collaborateurApi; context = _contexte; + transformDTO = _transformDTO; } #endregion @@ -259,6 +266,125 @@ namespace EPAServeur.Services return collaborateursDTO; } + /// + /// Transformer un collaborateur en collaborateurDTO de manière asynchrone. + /// + /// Collaborateur à transformer en collaborateurDTO + /// Indiquer si le référent du collaborateur doit être récupéré ou non + /// Renvoie la transformation DTO du collaborateur + public async Task GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent) + { + CollaborateurDTO collaborateurDTO = new CollaborateurDTO() + { + Id = collaborateur.Id, + Prenom = collaborateur.Prenom, + Nom = collaborateur.Nom, + MailApside = collaborateur.MailApside, + DateArrivee = collaborateur.DateArrivee, + + }; + collaborateurDTO.BusinessUnit = transformDTO.GetBusinessUnitDTO(collaborateur.BusinessUnit); + //Si le référent du collaborateur doit être récupérer en même temps + if (chercherReferent) + collaborateurDTO.Referent = await GetReferentAsync(collaborateurDTO); + return collaborateurDTO; + } + + /// + /// Récupérer une liste de CollaborateurDTO contenant les collaborateurs et les référents. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(List participationsFormation) + { + if (participationsFormation == null || participationsFormation.Count == 0) + return null; + + List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer une liste de CollaborateurDTO contenant les collaborateurs et les référents. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(IEnumerable participationsFormation) + { + if (participationsFormation == null || !participationsFormation.Any()) + return null; + + List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + + /// + /// Récupérer le collaborateur et le référent qui sont présent dans l'EP qui est lié à l'engagement. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(Engagement engagement) + { + if (engagement == null) + return null; + + List guids = new List(); + + guids.Add((Guid?)engagement.Ep.IdCollaborateur); + guids.Add(engagement.Ep.IdReferent); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer les collaborateurs et les référents qui sont présent dans les EP qui sont liés aux engagements. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(IEnumerable engagements) + { + if (engagements == null || !engagements.Any()) + return null; + + List guids = engagements.SelectMany(engagement => new[] { (Guid?)engagement.Ep.IdCollaborateur, engagement.Ep.IdReferent }).ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer le collaborateur et le référent qui sont présent dans les EP. + /// + /// + /// + public async Task> GetCollaborateurDTOsAsync(IEnumerable eps) + { + if (eps == null || !eps.Any()) + return null; + + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); + + return await GetCollaborateurDTOsAsync(guids); + } + + /// + /// Récupérer le référent EP d'un collaborateur de manière asynchrone s'il existe. + /// + /// Le collaborateur dont on cherche le référent EP + /// Le référent EP du collaborateur + public async Task GetReferentAsync(CollaborateurDTO collaborateur) + { + ReferentEP referentEP = await context.ReferentEP.FindAsync(collaborateur.Id); + //vérifier que le collaorateur a un référent EP + if (referentEP == null || referentEP.IdReferent == null || !referentEP.IdReferent.HasValue || referentEP.IdReferent.Value == null) + return null; + Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(referentEP.IdReferent); + if (referent == null) + return null; + return await GetCollaborateurDTOAsync(referent, false); + } #endregion @@ -337,93 +463,5 @@ namespace EPAServeur.Services } #endregion - - #region DTO To Object - - /// - /// Transformer une agence en agenceDTO - /// - /// agence à transformer en agenceDTO - /// Retourne la transformation DTO de l'agence - private AgenceDTO GetAgenceDTO(Agence agence) - { - if (agence == null) - return null; - AgenceDTO agenceDTO = new AgenceDTO() - { - Id = agence.Id, - Nom = agence.Nom, - Bu = new List() - }; - agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO() - { - Id = bu.Id, - Nom = bu.Nom - }).ToList(); - return agenceDTO; - } - - /// - /// Transforme une businessUnit en businessUnitDTO - /// - /// businessUnit à transformer en businessUnitDTO - /// Retourne la transformation DTO de la businessUnit - private BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit) - { - if (businessUnit == null) - return null; - BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO() - { - Id = businessUnit.Id, - Nom = businessUnit.Nom, - Agence = GetAgenceDTO(businessUnit.Agence) - }; - return businessUnitDTO; - } - - - /// - /// Transforme un collaborateur en collaborateurDTO de manière asynchrone - /// - /// collaborateur à transformer en collaborateurDTO - /// Indiquer si le référent du collaborateur doit être récupéré ou non - /// Renvoie la transformation DTO du collaborateur - private async Task GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent) - { - CollaborateurDTO collaborateurDTO = new CollaborateurDTO() - { - Id = collaborateur.Id, - Prenom = collaborateur.Prenom, - Nom = collaborateur.Nom, - MailApside = collaborateur.MailApside, - DateArrivee = collaborateur.DateArrivee, - - }; - collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit); - //Si le référent du collaborateur doit être récupérer en même temps - if (chercherReferent) - collaborateurDTO.Referent = await GetReferentAsync(collaborateurDTO); - return collaborateurDTO; - } - - - - /// - /// Récupérer le référent EP d'un collaborateur de manière asynchrone si il existe - /// - /// Le collaborateur dont on cherche le référent EP - /// Le référent EP du collaborateur - private async Task GetReferentAsync(CollaborateurDTO collaborateur) - { - ReferentEP referentEP = await context.ReferentEP.FindAsync(collaborateur.Id); - //vérifier que le collaorateur a un référent EP - if (referentEP == null || referentEP.IdReferent == null || !referentEP.IdReferent.HasValue || referentEP.IdReferent.Value == null) - return null; - Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(referentEP.IdReferent); - if (referent == null) - return null; - return await GetCollaborateurDTOAsync(referent, false); - } - #endregion } } diff --git a/EPAServeur/Services/DemandeDelegationService.cs b/EPAServeur/Services/DemandeDelegationService.cs index 48347e5..1ceb7de 100644 --- a/EPAServeur/Services/DemandeDelegationService.cs +++ b/EPAServeur/Services/DemandeDelegationService.cs @@ -17,16 +17,29 @@ namespace EPAServeur.Services public class DemandeDelegationService : IDemandeDelegationService { #region variables + /// + /// Accès et gestion de la base de données + /// private readonly EpContext context; + + /// + /// Accès et service collaborateur + /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + #endregion #region constructeur - public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context) + public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context, ITransformDTO _transformDTO) { context = _context; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -46,7 +59,7 @@ namespace EPAServeur.Services throw new ReferentNotFoundException(); } - return demandesDelegation.Select(d => GetDemandeDelegationDTO(d, referent, collaborateursDTO)); + return demandesDelegation.Select(d => transformDTO.GetDemandeDelegationDTO(d, referent, collaborateursDTO)); } @@ -102,36 +115,6 @@ namespace EPAServeur.Services return demandeDelegationDTO; } - - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurs) - { - return new EpInformationDTO() - { - Id = ep.IdEP, - Collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)), - Referent = collaborateurs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)), - DatePrevisionnelle = ep.DatePrevisionnelle, - DateDisponibilite = ep.DateDisponibilite, - Statut = ep.Statut, - Type = ep.TypeEP, - Obligatoire = ep.Obligatoire, - }; - } - - private DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable collaborateurs) - { - return new DemandeDelegationDTO() - { - Id = demande.IdDemandeDelegation, - DateDemande = demande.DateDemande, - EtatDemande = demande.EtatDemande, - Referent = referent, - RaisonDemande = demande.RaisonDemande, - Ep = GetEpInformationDTO(demande.Ep, collaborateurs) - }; - - } - #endregion diff --git a/EPAServeur/Services/EngagementService.cs b/EPAServeur/Services/EngagementService.cs index 3b35cd7..9e0f560 100644 --- a/EPAServeur/Services/EngagementService.cs +++ b/EPAServeur/Services/EngagementService.cs @@ -27,6 +27,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + /// /// Nombre d'éléments min à afficher par page /// @@ -60,10 +65,11 @@ namespace EPAServeur.Services /// Constructeur de la classe EngagementService /// /// - public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService) + public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO) { epContext = _epContext; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -96,9 +102,9 @@ namespace EPAServeur.Services engagements = await query.ToListAsync(); - collaborateurDTOs = await GetCollaborateurDTOs(engagements); + collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagements); - engagementDTOs = engagements.Select(engagement => GetEngagementDTO(engagement, collaborateurDTOs)); + engagementDTOs = engagements.Select(engagement => transformDTO.GetEngagementDTO(engagement, collaborateurDTOs)); engagementDTOs = CollaborateurFilter(engagementDTOs, texte); return engagementDTOs; @@ -118,9 +124,9 @@ namespace EPAServeur.Services engagements = await query.ToListAsync(); - collaborateurDTOs = await GetCollaborateurDTOs(engagements); + collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagements); - engagementDTOs = engagements.Select(engagement => GetEngagementDTO(engagement, collaborateurDTOs)); + engagementDTOs = engagements.Select(engagement => transformDTO.GetEngagementDTO(engagement, collaborateurDTOs)); engagementDTOs = CollaborateurFilter(engagementDTOs, texte); count = engagementDTOs.Count(); @@ -149,13 +155,13 @@ namespace EPAServeur.Services if (engagement == null) throw new EngagementNotFoundException(); - collaborateurDTOs = await GetCollaborateurDTOs(engagement); + collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagement); - engagement = SetReponseEngagement(engagement, engagementDTO); + engagement = transformDTO.SetReponseEngagement(engagement, engagementDTO); await epContext.SaveChangesAsync(); - return GetEngagementDTO(engagement, collaborateurDTOs); + return transformDTO.GetEngagementDTO(engagement, collaborateurDTOs); } @@ -323,134 +329,6 @@ namespace EPAServeur.Services return query.Skip(skip).Take(take); } - - #region Object to DTO - - /// - /// Récupère un objet EngagementDTO en fonction d'un objet Engagement et d'une liste de CollaborateurDTO - /// - /// - /// - private EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable collaborateurDTOs) - { - if (engagement == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - EngagementDTO engagementDTO = new EngagementDTO() - { - Id = engagement.IdEngagement, - Action = engagement.Action, - DateLimite = engagement.DateLimite, - Dispositif = engagement.Dispositif, - Modalite = engagement.Modalite, - RaisonNonRealisable = engagement.RaisonNonRealisable, - EtatEngagement = engagement.EtatEngagement, - Ep = GetEpInformationDTO(engagement.Ep, collaborateurDTOs) - }; - - return engagementDTO; - } - - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null si l'engagement est null. - /// - /// - /// - private async Task> GetCollaborateurDTOs(Engagement engagement) - { - if (engagement == null) - return null; - - List guids = new List(); - - guids.Add((Guid?)engagement.Ep.IdCollaborateur); - guids.Add(engagement.Ep.IdReferent); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; - } - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucun engagement. - /// - /// - /// - private async Task> GetCollaborateurDTOs(IEnumerable engagements) - { - if (engagements == null || !engagements.Any()) - return null; - - List guids = engagements.SelectMany(engagement => new[] { (Guid?)engagement.Ep.IdCollaborateur, engagement.Ep.IdReferent }).ToList(); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); - } - - /// - /// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO - /// - /// - /// - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurDTOs) - { - CollaborateurDTO collaborateur; - CollaborateurDTO referent; - - if (ep == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - 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 - - /// - /// Modifie la réponse d'un objet Engagement en fonction d'un objet EngagementDTO - /// - /// - /// - /// - private Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO) - { - if (engagement == null || engagementDTO == null) - return null; - - engagement.EtatEngagement = engagementDTO.EtatEngagement; - - switch (engagement.EtatEngagement) - { - case EtatEngagement.NonRealisable: - engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; - break; - case EtatEngagement.DateLimitePassee: - engagement.RaisonNonRealisable = "La date limite pour respecter l'engagement est passée."; - break; - default: - engagement.RaisonNonRealisable = null; - break; - } - - return engagement; - } - - #endregion - #endregion } diff --git a/EPAServeur/Services/EpInformationService.cs b/EPAServeur/Services/EpInformationService.cs index 49fb819..cc41351 100644 --- a/EPAServeur/Services/EpInformationService.cs +++ b/EPAServeur/Services/EpInformationService.cs @@ -13,18 +13,43 @@ namespace EPAServeur.Services public class EpInformationService : IEpInformationService { #region Variables - private EpContext context; - private ICollaborateurService collaborateurService; - private int? minParPage = 5; - private int? maxParPage = 100; - private int? defaultParPage = 15; + /// + /// Accès et gestion de la base de données + /// + private readonly EpContext context; + + /// + /// Accès et service collaborateur + /// + private readonly ICollaborateurService collaborateurService; + + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + + /// + /// Nombre d'éléments min à afficher par page + /// + private readonly int minParPage = 5; + + /// + /// Nom d'éléments max à affichar par page + /// + private readonly int maxParPage = 100; + + /// + /// Nombre d'éléments à afficher par défaut par page + /// + private readonly int defaultParPage = 15; #endregion #region constructeur - public EpInformationService(EpContext context, ICollaborateurService collaborateurService) + public EpInformationService(EpContext context, ICollaborateurService collaborateurService, ITransformDTO _transformDTO) { this.context = context; this.collaborateurService = collaborateurService; + this.transformDTO = _transformDTO; } #endregion @@ -105,7 +130,7 @@ namespace EPAServeur.Services if (ep == null) return null; IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(new List() { ep.IdReferent, ep.IdCollaborateur }); - return EpToEpDTO(ep, collaborateurDTOs); + return transformDTO.EpToEpDTO(ep, collaborateurDTOs); } #endregion @@ -116,8 +141,8 @@ namespace EPAServeur.Services { eps = TriDate(eps, dateDebut, dateFin); - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(eps); - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(eps); + IEnumerable epDTOs = eps.Select(ep => transformDTO.EpToEpDTO(ep, collaborateurDTOs)); if (!string.IsNullOrEmpty(texte)) epDTOs = epDTOs.Where(e => TriTexte(e, texte)); @@ -135,8 +160,8 @@ namespace EPAServeur.Services eps = TriDate(eps, dateDebut, dateFin); - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(eps); - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(eps); + IEnumerable epDTOs = eps.Select(ep => transformDTO.EpToEpDTO(ep, collaborateurDTOs)); if(!string.IsNullOrEmpty(texte)) epDTOs = epDTOs.Where(e => TriTexte(e, texte)); @@ -154,22 +179,6 @@ namespace EPAServeur.Services return eps; } - - private EpInformationDTO EpToEpDTO(Ep ep, IEnumerable collaborateurDTOs) - { - return new EpInformationDTO() - { - Id = ep.IdEP, - Collaborateur = collaborateurDTOs.Where(c => c.Id.Equals(ep.IdCollaborateur)).FirstOrDefault(), - DateDisponibilite = ep.DateDisponibilite, - DatePrevisionnelle = ep.DatePrevisionnelle, - Obligatoire = ep.Obligatoire, - Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)), - Statut = ep.Statut, - Type = ep.TypeEP - }; - } - private IEnumerable TriColonne(IEnumerable epDTOs, string tri) { switch (tri) @@ -223,12 +232,6 @@ namespace EPAServeur.Services return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower()); } - private async Task> GetCollaborateurDTOs(IEnumerable eps) - { - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); - return await collaborateurService.GetCollaborateurDTOsAsync(guids); - } - #endregion } } diff --git a/EPAServeur/Services/FormationService.cs b/EPAServeur/Services/FormationService.cs index fb0b113..4790b04 100644 --- a/EPAServeur/Services/FormationService.cs +++ b/EPAServeur/Services/FormationService.cs @@ -26,6 +26,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + /// /// Nombre d'éléments min à afficher par page /// @@ -59,10 +64,11 @@ namespace EPAServeur.Services /// Constructeur de la classe FormationService /// /// - public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService) + public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO) { epContext = _epContext; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -91,12 +97,12 @@ namespace EPAServeur.Services if (formation.ParticipationsFormation.Count > 0) { - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(formation.ParticipationsFormation); - return GetFormationDTO(formation, collaborateurDTOs); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(formation.ParticipationsFormation); + return transformDTO.GetFormationDTO(formation, collaborateurDTOs); } else { - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } } @@ -137,7 +143,7 @@ namespace EPAServeur.Services formations = await query.ToListAsync(); - formationDTOs = formations.Select(formation => GetFormationDetailsDTO(formation)); + formationDTOs = formations.Select(formation => transformDTO.GetFormationDetailsDTO(formation)); return formationDTOs; } @@ -187,7 +193,7 @@ namespace EPAServeur.Services modeFormations = await epContext.ModeFormation.ToListAsync(); - modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); + modeFormationDTOs = modeFormations.Select(modeFormation => transformDTO.GetModeFormationDTO(modeFormation)); return modeFormationDTOs; } @@ -203,7 +209,7 @@ namespace EPAServeur.Services origineFormations = await epContext.OrigineFormation.ToListAsync(); - origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); + origineFormationDTOs = origineFormations.Select(origineFormation => transformDTO.GetOrigineFormationDTO(origineFormation)); return origineFormationDTOs; } @@ -219,7 +225,7 @@ namespace EPAServeur.Services statutFormations = await epContext.StatutFormation.ToListAsync(); - statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); + statutFormationDTOs = statutFormations.Select(statutFormation => transformDTO.GetStatutFormationDTO(statutFormation)); return statutFormationDTOs; } @@ -235,7 +241,7 @@ namespace EPAServeur.Services typeFormations = await epContext.TypeFormation.ToListAsync(); - typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); + typeFormationDTOs = typeFormations.Select(typeFormation => transformDTO.GetTypeFormationDTO(typeFormation)); return typeFormationDTOs; } @@ -250,7 +256,7 @@ namespace EPAServeur.Services IsFormationValide(formationDTO); Formation formation = new Formation(); - formation = SetFormation(formation, formationDTO); + formation = transformDTO.SetFormation(formation, formationDTO); epContext.StatutFormation.Attach(formation.Statut); epContext.OrigineFormation.Attach(formation.Origine); @@ -260,7 +266,7 @@ namespace EPAServeur.Services await epContext.SaveChangesAsync(); - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } /// @@ -289,10 +295,10 @@ namespace EPAServeur.Services throw new FormationNotFoundException(string.Format("Aucune formation trouvée avec l'id suivant: {0}.", idFormation)); - formation = SetFormation(formation, formationDTO); + formation = transformDTO.SetFormation(formation, formationDTO); await epContext.SaveChangesAsync(); - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } /// @@ -318,7 +324,7 @@ namespace EPAServeur.Services await epContext.SaveChangesAsync(); - return GetFormationDTO(formation); + return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation); } #endregion @@ -538,385 +544,6 @@ namespace EPAServeur.Services } - #region Object to DTO - /// - /// Récuperer un objet FormationDTO en fonction d'un objet Formation - /// - /// - /// - private FormationDTO GetFormationDTO(Formation formation) - { - if (formation == null) - return null; - - FormationDTO formationDTO = new FormationDTO() - { - Id = formation.IdFormation, - Intitule = formation.Intitule, - IdAgence = formation.IdAgence, - DateDebut = formation.DateDebut, - DateFin = formation.DateFin, - Heure = formation.Heure, - Jour = formation.Jour, - Organisme = formation.Organisme, - EstCertifiee = formation.EstCertifiee, - EstRealisee = formation.EstRealisee, - Origine = GetOrigineFormationDTO(formation.Origine), - Statut = GetStatutFormationDTO(formation.Statut), - Mode = GetModeFormationDTO(formation.ModeFormation), - Type = GetTypeFormationDTO(formation.TypeFormation), - }; - - return formationDTO; - } - - /// - /// Récuperer un objet FormationDTO avec des participations en fonction d'un objet Formation et d'une liste de CollaborateurDTO - /// - /// - /// - private FormationDTO GetFormationDTO(Formation formation, IEnumerable collaborateurDTOs) - { - if (formation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - FormationDTO formationDTO = new FormationDTO() - { - Id = formation.IdFormation, - Intitule = formation.Intitule, - IdAgence = formation.IdAgence, - DateDebut = formation.DateDebut, - DateFin = formation.DateFin, - Heure = formation.Heure, - Jour = formation.Jour, - Organisme = formation.Organisme, - EstCertifiee = formation.EstCertifiee, - EstRealisee = formation.EstRealisee, - Origine = GetOrigineFormationDTO(formation.Origine), - Statut = GetStatutFormationDTO(formation.Statut), - Mode = GetModeFormationDTO(formation.ModeFormation), - Type = GetTypeFormationDTO(formation.TypeFormation), - Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation, collaborateurDTOs) - }; - - return formationDTO; - } - - /// - /// Récuperer un objet FormationDetailsDTO en fonction d'un objet Formation - /// - /// - /// - private FormationDetailsDTO GetFormationDetailsDTO(Formation formation) - { - if (formation == null) - return null; - - FormationDetailsDTO formationDTO = new FormationDetailsDTO() - { - Id = formation.IdFormation, - Intitule = formation.Intitule, - DateDebut = formation.DateDebut, - DateFin = formation.DateFin, - Organisme = formation.Organisme, - EstCertifiee = formation.EstCertifiee, - NbParticipations = formation.ParticipationsFormation.Count, - Origine = GetOrigineFormationDTO(formation.Origine), - Statut = GetStatutFormationDTO(formation.Statut), - }; - - return formationDTO; - } - - /// - /// Récuperer un objet OrigineFormationDTO en fonction d'un objet OrigineFormation - /// - /// - /// - private OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation) - { - if (origineFormation == null) - return null; - - OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO() - { - Id = origineFormation.IdOrigineFormation, - Libelle = origineFormation.Libelle - }; - - return origineFormationDTO; - } - - /// - /// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation - /// - /// - /// - private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation) - { - if (statutFormation == null) - return null; - - StatutFormationDTO statutFormationDTO = new StatutFormationDTO() - { - Id = statutFormation.IdStatutFormation, - Libelle = statutFormation.Libelle - }; - - return statutFormationDTO; - } - - /// - /// Récuperer un objet ModeFormationDTO en fonction d'un objet ModeFormation - /// - /// - /// - private ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation) - { - if (modeFormation == null) - return null; - - ModeFormationDTO modeFormationDTO = new ModeFormationDTO() - { - Id = modeFormation.IdModeFormation, - Libelle = modeFormation.Libelle - }; - - return modeFormationDTO; - } - - /// - /// Récuperer un objet TypeFormationDTO en fonction d'un objet TypeFormation - /// - /// - /// - private TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation) - { - if (typeFormation == null) - return null; - - TypeFormationDTO typeFormationDTO = new TypeFormationDTO() - { - Id = typeFormation.IdTypeFormation, - Libelle = typeFormation.Libelle - }; - - return typeFormationDTO; - } - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation. - /// - /// - /// - private async Task> GetCollaborateurDTOs(List participationsFormation) - { - if (participationsFormation == null || participationsFormation.Count == 0) - return null; - - List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; - } - - /// - /// Récuperer une liste de ParticipationFormationDTO en fonction d'une liste de ParticipationFormation et d'une liste de CollaborateurDTO. Retourne null s'il n'y a aucune participation ou aucun collaborateur. - /// - /// - /// - private List GetParticipationsFormationDTO(List participationsFormation, IEnumerable collaborateurDTOs) - { - List participationFormationDTOs; - - if (participationsFormation == null || participationsFormation.Count == 0 || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs)) - .OrderBy(participationFormation => participationFormation.Collaborateur.Nom) - .ThenBy(participationFormation => participationFormation.Collaborateur.Prenom).ToList(); - - return participationFormationDTOs; - } - - /// - /// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - 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; - } - - /// - /// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur); - } - - /// - /// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO - /// - /// - /// - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurDTOs) - { - CollaborateurDTO collaborateur; - CollaborateurDTO referent; - - if (ep == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - 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 - - /// - /// Modifier un objet Formation en fonction d'un objet FormationDTO - /// - /// - /// - /// - private Formation SetFormation(Formation formation, FormationDTO formationDTO) - { - if (formation == null || formationDTO == null) - return null; - - formation.Intitule = formationDTO.Intitule; - formation.IdAgence = formationDTO.IdAgence.Value; - formation.DateDebut = formationDTO.DateDebut.Value; - formation.DateFin = formationDTO.DateFin.Value; - formation.Heure = Convert.ToInt32(formationDTO.Heure.Value); - formation.Jour = Convert.ToInt32(formationDTO.Jour.Value); - formation.Organisme = formationDTO.Organisme; - formation.EstCertifiee = formationDTO.EstCertifiee.Value; - //formation.EstRealisee = formationDTO.EstRealisee.Value; - formation.Origine = GetOrigineFormation(formationDTO.Origine); - formation.Statut = GetStatutFormation(formationDTO.Statut); - formation.ModeFormation = GetModeFormation(formationDTO.Mode); - formation.TypeFormation = GetTypeFormation(formationDTO.Type); - - return formation; - } - - /// - /// Récuperer un objet OrigineFormation en fonction d'un objet OrigineFormationDTO - /// - /// - /// - private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO) - { - if (origineFormationDTO == null) - return null; - - OrigineFormation origineFormation = new OrigineFormation() - { - IdOrigineFormation = origineFormationDTO.Id.Value, - Libelle = origineFormationDTO.Libelle - }; - - return origineFormation; - } - - /// - /// Récuperer un objet StatutFormation en fonction d'un objet StatutFormationDTO - /// - /// - /// - private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO) - { - if (statutFormationDTO == null) - return null; - - StatutFormation statutFormation = new StatutFormation() - { - IdStatutFormation = statutFormationDTO.Id.Value, - Libelle = statutFormationDTO.Libelle - }; - - return statutFormation; - } - - /// - /// Récuperer un objet ModeFormation en fonction d'un objet ModeFormationDTO - /// - /// - /// - private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO) - { - if (modeFormationDTO == null) - return null; - - ModeFormation modeFormation = new ModeFormation() - { - IdModeFormation = modeFormationDTO.Id.Value, - Libelle = modeFormationDTO.Libelle - }; - - return modeFormation; - } - - /// - /// Récuperer un objet TypeFormation en fonction d'un objet TypeFormationDTO - /// - /// - /// - private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO) - { - if (typeFormationDTO == null) - return null; - - TypeFormation typeFormation = new TypeFormation() - { - IdTypeFormation = typeFormationDTO.Id.Value, - Libelle = typeFormationDTO.Libelle - }; - - return typeFormation; - } - - #endregion - #endregion } diff --git a/EPAServeur/Services/NoteService.cs b/EPAServeur/Services/NoteService.cs index 00f0dcf..736b939 100644 --- a/EPAServeur/Services/NoteService.cs +++ b/EPAServeur/Services/NoteService.cs @@ -32,13 +32,19 @@ namespace EPAServeur.Services /// Service collaborateur pour récupérer les données collaborateurs au format DTO /// private readonly ICollaborateurService collaborateurService; + + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; #endregion #region Constructeurs - public NoteService(ICollaborateurApi _collaborateurApi, ICollaborateurService _collaborateurService, EpContext _context) + public NoteService(ICollaborateurApi _collaborateurApi, ICollaborateurService _collaborateurService, EpContext _context, ITransformDTO _transformDTO) { collaborateurService = _collaborateurService; collaborateurApi = _collaborateurApi; context = _context; + transformDTO = _transformDTO; } #endregion @@ -66,7 +72,7 @@ namespace EPAServeur.Services //transformer la note DTO en Note - Note note = DetailsNoteDTOToNouvelleNote(nouvelleNote); + Note note = transformDTO.DetailsNoteDTOToNouvelleNote(nouvelleNote); //ajouter la note et sauvegarder await context.Note.AddAsync(note); @@ -111,7 +117,7 @@ namespace EPAServeur.Services if (auteur == null) throw new ReferentNotFoundException("L'auteur de la note n'existe pas"); - return NoteToDetailSDTO(note, await collaborateurService.GetCollaborateurByIdAsync(note.IdCollaborateur)); + return transformDTO.NoteToDetailSDTO(note, await collaborateurService.GetCollaborateurByIdAsync(note.IdCollaborateur)); } /// @@ -134,7 +140,7 @@ namespace EPAServeur.Services List guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList(); IEnumerable collaborateurs = await collaborateurApi.ChercherCollabAsync(guids); - IEnumerable AffichageNoteDTO = notes.Select(note => NoteToAffichageDTO(note, collaborateurs)); + IEnumerable AffichageNoteDTO = notes.Select(note => transformDTO.NoteToAffichageDTO(note, collaborateurs)); int skip = (numPage.Value - 1) * parPage.Value; @@ -173,7 +179,7 @@ namespace EPAServeur.Services List guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList(); IEnumerable collaborateurs = await collaborateurApi.ChercherCollabAsync(guids); - IEnumerable AffichageNoteDTO = notes.Select(note => NoteToAffichageDTO(note, collaborateurs)); + IEnumerable AffichageNoteDTO = notes.Select(note => transformDTO.NoteToAffichageDTO(note, collaborateurs)); if (texte != null) { @@ -274,77 +280,5 @@ namespace EPAServeur.Services } #endregion - #region ObjectToDTO - - - /// - /// Transformer un objet note en objet pour afficher un note dans dans un tableau - /// - /// Note à transformer - /// Service collaborateur pour récupérer les informations des collaborateurs - /// La note transformée pour être affichée - private AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable collaborateurs) - { - Collaborateur collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(note.IdCollaborateur)); - string infoCollab = "Aucun collaborateur lié"; - if (collaborateur != null) - infoCollab = collaborateur.Nom + " " + collaborateur.Prenom; - AffichageNoteDTO affichage = new AffichageNoteDTO() - { - Id = note.IdNote, - IdCollaborateur = note.IdCollaborateur, - Collaborateur = infoCollab, - Titre = note.Titre, - DateMiseAJour = note.DateMiseAJour - }; - return affichage; - } - - - - /// - /// Transformatino d'une note en DetailsNoteDTO de manière asynchrone - /// - /// Note à transformer - /// Note transformer en DetailsNoteDTO - private DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur) - { - if (collaborateur == null) - throw new CollaborateurNotFoundException("Il est impossible de récupérer une note donc le collaborateur n'existe plus"); - DetailsNoteDTO details = new DetailsNoteDTO() - { - Id = note.IdNote, - DateCreation = note.DateCreation, - DateMiseAjour = note.DateMiseAJour, - Titre = note.Titre, - Texte = note.Texte, - IdAuteur = note.IdAuteur, - Collaborateur = collaborateur, - }; - return details; - } - #endregion - - #region DTOToObject - /// - /// Transformer l'objet DTO d'une note en note - /// - /// En général, de base, cette méthode est prévue pour être utilisée qu'à la création d'une nouvelle note, dateCreation et dateUpdate sont donc initialisée à ce moment là - /// Objet DTO à transformer en note - /// L'objet DTO transformé en note - private Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO) - { - Note note = new Note() - { - IdAuteur = detailsNoteDTO.IdAuteur.Value, - IdCollaborateur = detailsNoteDTO.Collaborateur.Id.Value, - Texte = detailsNoteDTO.Texte, - Titre = detailsNoteDTO.Titre, - DateCreation = detailsNoteDTO.DateCreation.Value, - DateMiseAJour = detailsNoteDTO.DateMiseAjour.Value - }; - return note; - } - #endregion } } diff --git a/EPAServeur/Services/ParticipationFormationService.cs b/EPAServeur/Services/ParticipationFormationService.cs index 37ff1f3..57459ec 100644 --- a/EPAServeur/Services/ParticipationFormationService.cs +++ b/EPAServeur/Services/ParticipationFormationService.cs @@ -28,6 +28,11 @@ namespace EPAServeur.Services /// private readonly ICollaborateurService collaborateurService; + /// + /// Accès au service permettant de transformer un modèle en dto + /// + private readonly ITransformDTO transformDTO; + #endregion #region Contructeurs @@ -36,10 +41,11 @@ namespace EPAServeur.Services /// Constructeur de la classe FormationService /// /// - public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService) + public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO) { epContext = _epContext; collaborateurService = _collaborateurService; + transformDTO = _transformDTO; } #endregion @@ -63,7 +69,7 @@ namespace EPAServeur.Services if (participationFormation == null) throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation)); - return GetEvaluationDTO(participationFormation); + return transformDTO.GetEvaluationDTO(participationFormation); } /// @@ -87,9 +93,9 @@ namespace EPAServeur.Services participationFormations = await query.ToListAsync(); - IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(participationFormations); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(participationFormations); - participationFormationDTOs = participationFormations.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs)); + participationFormationDTOs = participationFormations.Select(participationFormation => transformDTO.GetParticipationFormationDTO(participationFormation, collaborateurDTOs)); return participationFormationDTOs; } @@ -116,12 +122,12 @@ namespace EPAServeur.Services 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.Evaluation = evaluationDTO.Saisies.Select(s => transformDTO.GetSaisie(s)).ToList(); participationFormation.EstEvaluee = true; await epContext.SaveChangesAsync(); - return GetEvaluationDTO(participationFormation); + return transformDTO.GetEvaluationDTO(participationFormation); } #endregion @@ -163,238 +169,6 @@ namespace EPAServeur.Services throw new ParticipationFormationInvalidException("Toutes les saisies de type compétence ou notation doivent posséder une note."); } - #region Object to DTO - - /// - /// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null) - return null; - - if (collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO() - { - Id = participationFormation.IdParticipationFormation, - DateCreation = participationFormation.DateCreation, - Intitule = participationFormation.Formation.Intitule, - DateDebut = participationFormation.Formation.DateDebut, - EstEvaluee = participationFormation.EstEvaluee, - Statut = GetStatutFormationDTO(participationFormation.Formation.Statut), - Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs), - Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs) - }; - - return participationFormationDTO; - } - - - /// - /// Récuperer un objet EvaluationDTO en fonction d'un objet ParticipationFormation - /// - /// - /// - private EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation) - { - if (participationFormation == null) - return null; - - EvaluationDTO evaluationDTO = new EvaluationDTO() - { - Id = participationFormation.IdParticipationFormation, - Intitule = participationFormation.Formation.Intitule, - DateDebut = participationFormation.Formation.DateDebut, - EstCertifiee = participationFormation.Formation.EstCertifiee, - Saisies = participationFormation.Evaluation.Select(s => GetSaisieDTO(s)).ToList() - }; - - return evaluationDTO; - } - - /// - /// Récuperer un objet SaisieDTO en fonction d'un objet Saisie - /// - /// - /// - 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; - } - - /// - /// Récuperer un objet ChampDTO en fonction d'un objet Champ - /// - /// - /// - 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; - } - - /// - /// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation - /// - /// - /// - private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation) - { - if (statutFormation == null) - return null; - - StatutFormationDTO statutFormationDTO = new StatutFormationDTO() - { - Id = statutFormation.IdStatutFormation, - Libelle = statutFormation.Libelle - }; - return statutFormationDTO; - } - - /// - /// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation. - /// - /// - /// - private async Task> GetCollaborateurDTOs(IEnumerable participationsFormation) - { - if (participationsFormation == null || !participationsFormation.Any()) - return null; - - List guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList(); - - return await collaborateurService.GetCollaborateurDTOsAsync(guids); ; - } - - /// - /// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO - /// - /// - /// - private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) - { - if (participationFormation == null) - return null; - - if (collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur); - } - - /// - /// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO - /// - /// - /// - private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurDTOs) - { - CollaborateurDTO collaborateur; - CollaborateurDTO referent; - - if (ep == null) - return null; - - if (collaborateurDTOs == null || !collaborateurDTOs.Any()) - return null; - - - 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 - - /// - /// Récuperer un objet Saisie en fonction d'un objet SaisieDTO - /// - /// - /// - private Saisie GetSaisie(SaisieDTO saisieDTO) - { - if (saisieDTO == null) - return null; - - Saisie saisie = new Saisie() - { - //IdSaisie = saisieDTO.Id.Value, - Note = saisieDTO.Note, - Texte = saisieDTO.Texte, - Champ = GetChamp(saisieDTO.Champ), - TypeSaisie = saisieDTO.TypeSaisie - }; - - return saisie; - } - - /// - /// Récuperer un objet Champ en fonction d'un objet ChampDTO - /// - /// - /// - private Champ GetChamp(ChampDTO champDTO) - { - if (champDTO == null) - return null; - - 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 } diff --git a/EPAServeur/Services/TransformDTO.cs b/EPAServeur/Services/TransformDTO.cs new file mode 100644 index 0000000..75a5bf8 --- /dev/null +++ b/EPAServeur/Services/TransformDTO.cs @@ -0,0 +1,713 @@ +using EPAServeur.Context; +using EPAServeur.Exceptions; +using EPAServeur.IServices; +using EPAServeur.Models.EP; +using EPAServeur.Models.Formation; +using EPAServeur.Models.Notes; +using EPAServeur.Models.SaisieChamp; +using IO.Swagger.ApiCollaborateur; +using IO.Swagger.DTO; +using IO.Swagger.Enum; +using IO.Swagger.ModelCollaborateur; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EPAServeur.Services +{ + public class TransformDTO : ITransformDTO + { + + /// + /// Transformer un objet DetailsNoteDTO en objet Note. + /// + /// En général, de base, cette méthode est prévue pour être utilisée qu'à la création d'une nouvelle note, dateCreation et dateUpdate sont donc initialisée à ce moment là + /// Objet DTO à transformer en note + /// L'objet DTO transformé en note + public Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO) + { + Note note = new Note() + { + IdAuteur = detailsNoteDTO.IdAuteur.Value, + IdCollaborateur = detailsNoteDTO.Collaborateur.Id.Value, + Texte = detailsNoteDTO.Texte, + Titre = detailsNoteDTO.Titre, + DateCreation = detailsNoteDTO.DateCreation.Value, + DateMiseAJour = detailsNoteDTO.DateMiseAjour.Value + }; + return note; + } + + /// + /// Transformer un objet Ep en objet EpInformationDTO. + /// La liste des collaborateurs est utilisé pour alimenter le collaborateur et le référent de l'objet EpInformationDTO. + /// + /// + /// + /// + public EpInformationDTO EpToEpDTO(Ep ep, IEnumerable collaborateurDTOs) + { + return new EpInformationDTO() + { + Id = ep.IdEP, + Collaborateur = collaborateurDTOs.Where(c => c.Id.Equals(ep.IdCollaborateur)).FirstOrDefault(), + DateDisponibilite = ep.DateDisponibilite, + DatePrevisionnelle = ep.DatePrevisionnelle, + Obligatoire = ep.Obligatoire, + Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)), + Statut = ep.Statut, + Type = ep.TypeEP + }; + } + + /// + /// Transformer un objet Agence en objet AgenceDTO. + /// + /// + /// + public AgenceDTO GetAgenceDTO(Agence agence) + { + if (agence == null) + return null; + AgenceDTO agenceDTO = new AgenceDTO() + { + Id = agence.Id, + Nom = agence.Nom, + Bu = new List() + }; + agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO() + { + Id = bu.Id, + Nom = bu.Nom + }).ToList(); + return agenceDTO; + } + + /// + /// Transformer une objet BU en objet BusinessUnitDTO. + /// + /// + /// + public BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit) + { + if (businessUnit == null) + return null; + BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO() + { + Id = businessUnit.Id, + Nom = businessUnit.Nom, + Agence = GetAgenceDTO(businessUnit.Agence) + }; + return businessUnitDTO; + } + + /// + /// Récupérer un objet Champ en objet ChampDTO. + /// + /// + /// + public Champ GetChamp(ChampDTO champDTO) + { + if (champDTO == null) + return null; + + 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; + } + + /// + /// Transformer un objet Champ en objet ChampDTO. + /// + /// + /// + public 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; + } + + /// + /// Récupérer le collaborateur qui participe à la formation. + /// + /// + /// + /// + public CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) + { + if (participationFormation == null) + return null; + + if (collaborateurDTOs == null || !collaborateurDTOs.Any()) + return null; + + return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur); + } + + + /// + /// Transformer un objet DemandeDelegation en objet DemandeDelegationDTO. + /// L'objet CollaborateurDTO est utilisé pour alimenter la propriété Referent de l'objet DemandeDelegationDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Ep de l'objet DemandeDelegationDTO. + /// + /// + /// + /// + /// + public DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable collaborateurs) + { + return new DemandeDelegationDTO() + { + Id = demande.IdDemandeDelegation, + DateDemande = demande.DateDemande, + EtatDemande = demande.EtatDemande, + Referent = referent, + RaisonDemande = demande.RaisonDemande, + Ep = GetEpInformationDTO(demande.Ep, collaborateurs) + }; + } + + /// + /// Transformer un objet Engagement en objet EngagementDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Ep de l'objet EngagementDTO. + /// + /// + /// + /// + public EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable collaborateurDTOs) + { + if (engagement == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) + return null; + + EngagementDTO engagementDTO = new EngagementDTO() + { + Id = engagement.IdEngagement, + Action = engagement.Action, + DateLimite = engagement.DateLimite, + Dispositif = engagement.Dispositif, + Modalite = engagement.Modalite, + RaisonNonRealisable = engagement.RaisonNonRealisable, + EtatEngagement = engagement.EtatEngagement, + Ep = GetEpInformationDTO(engagement.Ep, collaborateurDTOs) + }; + + return engagementDTO; + } + + /// + /// Transformer un objet Ep en objet EpInformationDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Referent de l'objet EpInformationDTO. + /// + /// + /// + /// + public EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable collaborateurs) + { + CollaborateurDTO collaborateur; + CollaborateurDTO referent; + + if (ep == null || collaborateurs == null || !collaborateurs.Any()) + return null; + + collaborateur = collaborateurs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur); + referent = collaborateurs.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; + } + + /// + /// Transformer un objet ParticipationFormation en objet EvaluationDTO. + /// + /// + /// + public EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation) + { + if (participationFormation == null) + return null; + + EvaluationDTO evaluationDTO = new EvaluationDTO() + { + Id = participationFormation.IdParticipationFormation, + Intitule = participationFormation.Formation.Intitule, + DateDebut = participationFormation.Formation.DateDebut, + EstCertifiee = participationFormation.Formation.EstCertifiee, + Saisies = participationFormation.Evaluation.Select(s => GetSaisieDTO(s)).ToList() + }; + + return evaluationDTO; + } + + /// + /// Transformer un objet Formation en objet FormationDetailsDTO. + /// + /// + /// + public FormationDetailsDTO GetFormationDetailsDTO(Formation formation) + { + if (formation == null) + return null; + + FormationDetailsDTO formationDTO = new FormationDetailsDTO() + { + Id = formation.IdFormation, + Intitule = formation.Intitule, + DateDebut = formation.DateDebut, + DateFin = formation.DateFin, + Organisme = formation.Organisme, + EstCertifiee = formation.EstCertifiee, + NbParticipations = formation.ParticipationsFormation.Count, + Origine = GetOrigineFormationDTO(formation.Origine), + Statut = GetStatutFormationDTO(formation.Statut), + }; + + return formationDTO; + } + + /// + /// Transformer un objet Formation en objet FormationDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Participations de l'objet FormationDTO. + /// + /// + /// + /// + public FormationDTO GetFormationDTO(Formation formation, IEnumerable collaborateurDTOs) + { + if (formation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) + return null; + + FormationDTO formationDTO = new FormationDTO() + { + Id = formation.IdFormation, + Intitule = formation.Intitule, + IdAgence = formation.IdAgence, + DateDebut = formation.DateDebut, + DateFin = formation.DateFin, + Heure = formation.Heure, + Jour = formation.Jour, + Organisme = formation.Organisme, + EstCertifiee = formation.EstCertifiee, + EstRealisee = formation.EstRealisee, + Origine = GetOrigineFormationDTO(formation.Origine), + Statut = GetStatutFormationDTO(formation.Statut), + Mode = GetModeFormationDTO(formation.ModeFormation), + Type = GetTypeFormationDTO(formation.TypeFormation), + Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation, collaborateurDTOs) + }; + + return formationDTO; + } + + /// + /// Transformer un objet Formation en objet FormationDTO et laisser la propriété Participations de l'objet FormationDTO null. + /// + /// + /// + public FormationDTO GetFormationDTOWhitoutParticipationFormation(Formation formation) + { + if (formation == null) + return null; + + FormationDTO formationDTO = new FormationDTO() + { + Id = formation.IdFormation, + Intitule = formation.Intitule, + IdAgence = formation.IdAgence, + DateDebut = formation.DateDebut, + DateFin = formation.DateFin, + Heure = formation.Heure, + Jour = formation.Jour, + Organisme = formation.Organisme, + EstCertifiee = formation.EstCertifiee, + EstRealisee = formation.EstRealisee, + Origine = GetOrigineFormationDTO(formation.Origine), + Statut = GetStatutFormationDTO(formation.Statut), + Mode = GetModeFormationDTO(formation.ModeFormation), + Type = GetTypeFormationDTO(formation.TypeFormation), + }; + + return formationDTO; + } + + /// + /// Transformer un objet ModeFormationDTO en objet ModeFormation. + /// + /// + /// + public ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO) + { + if (modeFormationDTO == null) + return null; + + ModeFormation modeFormation = new ModeFormation() + { + IdModeFormation = modeFormationDTO.Id.Value, + Libelle = modeFormationDTO.Libelle + }; + + return modeFormation; + } + + /// + /// Transformer un objet ModeFormation en objet ModeFormationDTO. + /// + /// + /// + public ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation) + { + if (modeFormation == null) + return null; + + ModeFormationDTO modeFormationDTO = new ModeFormationDTO() + { + Id = modeFormation.IdModeFormation, + Libelle = modeFormation.Libelle + }; + + return modeFormationDTO; + } + + /// + /// Transformer un objet OrigineFormationDTO en objet OrigineFormation. + /// + /// + /// + public OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO) + { + if (origineFormationDTO == null) + return null; + + OrigineFormation origineFormation = new OrigineFormation() + { + IdOrigineFormation = origineFormationDTO.Id.Value, + Libelle = origineFormationDTO.Libelle + }; + + return origineFormation; + } + + + /// + /// Transformer un objet OrigineFormation en objet OrigineFormationDTO. + /// + /// + /// + public OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation) + { + if (origineFormation == null) + return null; + + OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO() + { + Id = origineFormation.IdOrigineFormation, + Libelle = origineFormation.Libelle + }; + + return origineFormationDTO; + } + + /// + /// Transformer un objet ParticipationFormation en objet ParticipationFormationDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO. + /// + /// + /// + /// + public ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable collaborateurDTOs) + { + if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any()) + return null; + + 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; + } + + /// + /// Transformer une liste d'objets ParticipationFormation en liste d'objets ParticipationFormationDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO. + /// + /// + /// + /// + public List GetParticipationsFormationDTO(List participationsFormation, IEnumerable collaborateurDTOs) + { + List participationFormationDTOs; + + if (participationsFormation == null || participationsFormation.Count == 0 || collaborateurDTOs == null || !collaborateurDTOs.Any()) + return null; + + participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs)) + .OrderBy(participationFormation => participationFormation.Collaborateur.Nom) + .ThenBy(participationFormation => participationFormation.Collaborateur.Prenom).ToList(); + + return participationFormationDTOs; + } + + + /// + /// Transformer un objet SaisieDTO en objet Saisie. + /// + /// + /// + public Saisie GetSaisie(SaisieDTO saisieDTO) + { + if (saisieDTO == null) + return null; + + Saisie saisie = new Saisie() + { + //IdSaisie = saisieDTO.Id.Value, + Note = saisieDTO.Note, + Texte = saisieDTO.Texte, + Champ = GetChamp(saisieDTO.Champ), + TypeSaisie = saisieDTO.TypeSaisie + }; + + return saisie; + } + + /// + /// Transformer un objet Saisie en objet SaisieDTO. + /// + /// + /// + public 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; + } + + /// + /// Transformer un objet StatutFormationDTO en objet StatutFormation. + /// + /// + /// + public StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO) + { + if (statutFormationDTO == null) + return null; + + StatutFormation statutFormation = new StatutFormation() + { + IdStatutFormation = statutFormationDTO.Id.Value, + Libelle = statutFormationDTO.Libelle + }; + + return statutFormation; + } + + /// + /// Transformer un objet StatutFormation en objet StatutFormationDTO. + /// + /// + /// + public StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation) + { + if (statutFormation == null) + return null; + + StatutFormationDTO statutFormationDTO = new StatutFormationDTO() + { + Id = statutFormation.IdStatutFormation, + Libelle = statutFormation.Libelle + }; + + return statutFormationDTO; + } + + /// + /// Transformer un objet TypeFormationDTO en objet TypeFormation. + /// + /// + /// + public TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO) + { + if (typeFormationDTO == null) + return null; + + TypeFormation typeFormation = new TypeFormation() + { + IdTypeFormation = typeFormationDTO.Id.Value, + Libelle = typeFormationDTO.Libelle + }; + + return typeFormation; + } + + /// + /// Transformer un objet TypeFormation en objet TypeFormationDTO. + /// + /// + /// + public TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation) + { + if (typeFormation == null) + return null; + + TypeFormationDTO typeFormationDTO = new TypeFormationDTO() + { + Id = typeFormation.IdTypeFormation, + Libelle = typeFormation.Libelle + }; + + return typeFormationDTO; + } + + /// + /// Transformer un objet Note en objet AffichageNoteDTO. + /// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur (nom et prénom) de l'objet AffichageNoteDTO. + /// + /// + /// + /// + public AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable collaborateurs) + { + Collaborateur collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(note.IdCollaborateur)); + string infoCollab = "Aucun collaborateur lié"; + if (collaborateur != null) + infoCollab = collaborateur.Nom + " " + collaborateur.Prenom; + AffichageNoteDTO affichage = new AffichageNoteDTO() + { + Id = note.IdNote, + IdCollaborateur = note.IdCollaborateur, + Collaborateur = infoCollab, + Titre = note.Titre, + DateMiseAJour = note.DateMiseAJour + }; + return affichage; + } + + /// + /// Transformer un objet Note en objet DetailsNoteDTO. + /// L'objet CollaborateurDTO est utilisé pour alimenter la propriété Collaborateur de l'objet DetailsNoteDTO. + /// + /// + /// + /// + public DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur) + { + if (collaborateur == null) + throw new CollaborateurNotFoundException("Il est impossible de récupérer une note donc le collaborateur n'existe plus"); + DetailsNoteDTO details = new DetailsNoteDTO() + { + Id = note.IdNote, + DateCreation = note.DateCreation, + DateMiseAjour = note.DateMiseAJour, + Titre = note.Titre, + Texte = note.Texte, + IdAuteur = note.IdAuteur, + Collaborateur = collaborateur, + }; + return details; + } + + /// + /// Mettre à jour un objet Formation en fonction d'un objet FormationDTO. + /// + /// + /// + /// + public Formation SetFormation(Formation formation, FormationDTO formationDTO) + { + if (formation == null || formationDTO == null) + return null; + + formation.Intitule = formationDTO.Intitule; + formation.IdAgence = formationDTO.IdAgence.Value; + formation.DateDebut = formationDTO.DateDebut.Value; + formation.DateFin = formationDTO.DateFin.Value; + formation.Heure = Convert.ToInt32(formationDTO.Heure.Value); + formation.Jour = Convert.ToInt32(formationDTO.Jour.Value); + formation.Organisme = formationDTO.Organisme; + formation.EstCertifiee = formationDTO.EstCertifiee.Value; + //formation.EstRealisee = formationDTO.EstRealisee.Value; + formation.Origine = GetOrigineFormation(formationDTO.Origine); + formation.Statut = GetStatutFormation(formationDTO.Statut); + formation.ModeFormation = GetModeFormation(formationDTO.Mode); + formation.TypeFormation = GetTypeFormation(formationDTO.Type); + + return formation; + } + + /// + /// Mettre à jour la réponse d'un objet Engagement en fonction d'un objet EngagementDTO. + /// + /// + /// + /// + public Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO) + { + if (engagement == null || engagementDTO == null) + return null; + + engagement.EtatEngagement = engagementDTO.EtatEngagement; + + switch (engagement.EtatEngagement) + { + case EtatEngagement.NonRealisable: + engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable; + break; + case EtatEngagement.DateLimitePassee: + engagement.RaisonNonRealisable = "La date limite pour respecter l'engagement est passée."; + break; + default: + engagement.RaisonNonRealisable = null; + break; + } + + return engagement; + } + } +} diff --git a/EPAServeur/Startup.cs b/EPAServeur/Startup.cs index 8cb5efc..aec2766 100644 --- a/EPAServeur/Startup.cs +++ b/EPAServeur/Startup.cs @@ -122,6 +122,7 @@ namespace EPAServeur //Services + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped();