diff --git a/EPAServeur.Tests/Services/EpInformationTests.cs b/EPAServeur.Tests/Services/EpInformationTests.cs index 66df45e..4729cbe 100644 --- a/EPAServeur.Tests/Services/EpInformationTests.cs +++ b/EPAServeur.Tests/Services/EpInformationTests.cs @@ -93,9 +93,11 @@ namespace EPAServeur.Tests.Services [TestCase("agence")] [TestCase("collaborateur")] [TestCase("referent")] - [TestCase("date")] + [TestCase("dateentretien")] [TestCase("typeep")] - [TestCase("etatep")] + [TestCase("statutep")] + [TestCase("datearrivee")] + [TestCase("datedisponibilite")] public async Task GetEpEnCours_TriColonneASC(string tri) { IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); @@ -117,15 +119,21 @@ namespace EPAServeur.Tests.Services case "referent": compare = (ep1.Referent.Nom + " " + ep1.Referent.Prenom).CompareTo((ep2.Referent.Nom + " " + ep2.Referent.Prenom)); break; - case "date": + case "dateentretien": compare = ep1.DatePrevisionnelle.Value.CompareTo(ep2.DatePrevisionnelle.Value); break; case "typeep": compare = ep1.Type.CompareTo(ep2.Type); break; - case "etatep": + case "statutep": compare = ep1.Statut.CompareTo(ep2.Statut); break; + case "datearrivee": + compare = ep1.Collaborateur.DateArrivee.Value.CompareTo(ep2.Collaborateur.DateArrivee.Value); + break; + case "datedisponibilite": + compare = ep1.DateDisponibilite.Value.CompareTo(ep2.DateDisponibilite.Value); + break; } Assert.IsTrue(compare <= 0); Assert.IsTrue(EstEpEnCours(ep1.Statut)); diff --git a/EPAServeur/Context/DataSeeder.cs b/EPAServeur/Context/DataSeeder.cs index 6e6f141..424d246 100644 --- a/EPAServeur/Context/DataSeeder.cs +++ b/EPAServeur/Context/DataSeeder.cs @@ -216,8 +216,6 @@ namespace EPAServeur.Context epContext.Ep.Add(epEnCours9); - //Orléans - //Paris //Ep signés @@ -366,11 +364,12 @@ namespace EPAServeur.Context IdEP = 9, IdCollaborateur = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"), IdReferent = Guid.Parse("aa36f34c-9041-42f5-9db3-6536fe7f1696"), - IdBu = 1, + IdBu = 2, Fonction = "Ingénieur en Etudes et Développement", TypeEP = TypeEp.EPA, NumeroEp = 1, DateCreation = new DateTime(2020, 7, 7), + DateDisponibilite = new DateTime(2020, 7, 7), DatePrevisionnelle = new DateTime(2020, 7, 8), Obligatoire = false, Statut = StatutEp.Signe, @@ -384,12 +383,13 @@ namespace EPAServeur.Context IdEP = 10, IdCollaborateur = Guid.Parse("301ba7f3-095e-4912-8998-a7c942dc5f23"), IdReferent = Guid.Parse("ea027734-ff0f-4308-8879-133a09fb3c46"), - IdBu = 3, + IdBu = 1, Fonction = "Ingénieur en Etudes et Développement", TypeEP = TypeEp.EPS, NumeroEp = 1, DateCreation = new DateTime(2020, 6, 1), DatePrevisionnelle = new DateTime(2020, 9, 25), + DateDisponibilite = new DateTime(2020, 8, 10), Obligatoire = false, Statut = StatutEp.Signe, CV = "CV.pdf", @@ -408,6 +408,7 @@ namespace EPAServeur.Context NumeroEp = 1, DateCreation = new DateTime(2020, 10, 15), DatePrevisionnelle = new DateTime(2020, 12, 4), + DateDisponibilite = new DateTime(2020, 10,30), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -900,6 +901,7 @@ namespace EPAServeur.Context NumeroEp = 1, DateCreation = new DateTime(2020, 1, 21, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 1, 22, 9, 0, 0), + DateDisponibilite = new DateTime(2019, 12, 23), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -912,12 +914,13 @@ namespace EPAServeur.Context IdEP = 13, IdCollaborateur = Guid.Parse("301ba7f3-095e-4912-8998-a7c942dc5f23"), IdReferent = Guid.Parse("ea027734-ff0f-4308-8879-133a09fb3c46"), - IdBu = 2, + IdBu = 1, Fonction = "Dev", TypeEP = TypeEp.EPS, NumeroEp = 3, DateCreation = new DateTime(2020, 2, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 2, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 1, 6), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -936,6 +939,7 @@ namespace EPAServeur.Context NumeroEp = 1, DateCreation = new DateTime(2020, 3, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 3, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 2, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -949,12 +953,13 @@ namespace EPAServeur.Context IdEP = 15, IdCollaborateur = Guid.Parse("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491"), IdReferent = Guid.Parse("25d2b0ce-5c95-4ccc-98bb-63b06c4ee4ad"), - IdBu = 2, + IdBu = 3, Fonction = "Dev", TypeEP = TypeEp.EPS, NumeroEp = 1, DateCreation = new DateTime(2020, 4, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 4, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 3, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -966,12 +971,13 @@ namespace EPAServeur.Context IdEP = 16, IdCollaborateur = Guid.Parse("0968ccd3-1ef5-4041-83f3-1c76afb02bbf"), IdReferent = Guid.Parse("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), - IdBu = 2, + IdBu = 3, Fonction = "Dev", TypeEP = TypeEp.EPA, NumeroEp = 1, DateCreation = new DateTime(2020, 5, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 5, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 4, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -985,12 +991,13 @@ namespace EPAServeur.Context IdEP = 17, IdCollaborateur = Guid.Parse("e7820f92-eab1-42f5-ae96-5c16e71ff1e6"), IdReferent = Guid.Parse("d4fc247b-015a-44d6-8f3e-a52f0902d2bf"), - IdBu = 2, + IdBu = 1, Fonction = "Dev", TypeEP = TypeEp.EPS, NumeroEp = 1, DateCreation = new DateTime(2020, 6, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 6, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 5, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -1004,12 +1011,13 @@ namespace EPAServeur.Context IdEP = 18, IdCollaborateur = Guid.Parse("1429be5b-9125-482c-80c4-c1d34afbd8d2"), IdReferent = Guid.Parse("3f276ab8-727a-4e26-ad5d-4d296158688e"), - IdBu = 2, + IdBu = 3, Fonction = "Dev", TypeEP = TypeEp.EPS, NumeroEp = 1, DateCreation = new DateTime(2020, 7, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 7, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 6, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -1023,12 +1031,13 @@ namespace EPAServeur.Context IdEP = 19, IdCollaborateur = Guid.Parse("13fbe621-1bc9-4f04-afde-b54ca076e239"), IdReferent = Guid.Parse("f1d14915-89f7-4c1a-a8e1-4148ed7d81d7"), - IdBu = 2, + IdBu = 3, Fonction = "Dev", TypeEP = TypeEp.EPASIXANS, NumeroEp = 1, DateCreation = new DateTime(2020, 8, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 8, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 7, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -1042,12 +1051,13 @@ namespace EPAServeur.Context IdEP = 20, IdCollaborateur = Guid.Parse("b5254c6c-7caa-435f-a4bb-e0cf92559832"), IdReferent = Guid.Parse("dfea9a3c-7896-444d-9aa0-61ae536091c1"), - IdBu = 2, + IdBu = 1, Fonction = "Dev", TypeEP = TypeEp.EPS, NumeroEp = 1, DateCreation = new DateTime(2020, 9, 22, 9, 0, 0), DatePrevisionnelle = new DateTime(2020, 9, 25, 9, 0, 0), + DateDisponibilite = new DateTime(2020, 9, 25), Obligatoire = false, Statut = StatutEp.SignatureReferent, CV = "CV.pdf", @@ -1784,7 +1794,7 @@ namespace EPAServeur.Context IdEP = 21, IdCollaborateur = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"), IdReferent = Guid.Parse("aa36f34c-9041-42f5-9db3-6536fe7f1696"), - IdBu = 1, + IdBu = 2, Fonction = "Ingénieur en Etudes et Développement", TypeEP = TypeEp.EPA, NumeroEp = 1, @@ -1877,7 +1887,7 @@ namespace EPAServeur.Context IdEP = 24, IdCollaborateur = Guid.Parse("13fbe621-1bc9-4f04-afde-b54ca076e239"), IdReferent = Guid.Parse("771f9129-5610-4f4b-a8eb-902a98d722be"), - IdBu = 1, + IdBu = 3, Fonction = "Ingénieur en Etudes et Développement", TypeEP = TypeEp.EPA, NumeroEp = 1, diff --git a/EPAServeur/Services/EpInformationService.cs b/EPAServeur/Services/EpInformationService.cs index 6b5cd99..1e72591 100644 --- a/EPAServeur/Services/EpInformationService.cs +++ b/EPAServeur/Services/EpInformationService.cs @@ -32,16 +32,19 @@ namespace EPAServeur.Services #region Services async public async Task> GetEPEnCours(List idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { - IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => EstEpEnCours(ep.Statut)); + + IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut)); eps = TriDate(eps, dateDebut, dateFin); - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList(); + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); - + IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); + if (texte != null && texte.Length > 0) + epDTOs = epDTOs.Where(e => TriTexte(e, texte)); epDTOs = TriColonne(epDTOs, tri); @@ -55,18 +58,18 @@ namespace EPAServeur.Services public async Task GetEPEnCoursCount(List idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { - IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => EstEpEnCours(ep.Statut)); + IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut)); eps = TriDate(eps, dateDebut, dateFin); - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList(); + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); + if( texte != null && texte.Length > 0) + epDTOs = epDTOs.Where(e => TriTexte(e, texte)); return epDTOs.Count(); } @@ -91,13 +94,14 @@ namespace EPAServeur.Services IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe); eps = TriDate(eps, dateDebut, dateFin); - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList(); + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); + if (texte != null && texte.Length > 0) + epDTOs = epDTOs.Where(e => TriTexte(e, texte)); epDTOs = TriColonne(epDTOs, tri); @@ -117,13 +121,14 @@ namespace EPAServeur.Services IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe); eps = TriDate(eps, dateDebut, dateFin); - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).ToList(); + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); + if (texte != null && texte.Length > 0) + epDTOs = epDTOs.Where(e => TriTexte(e, texte)); return epDTOs.Count(); } @@ -184,15 +189,21 @@ namespace EPAServeur.Services case "referent": epDTOs = epDTOs.OrderBy(e => e.Referent.Nom + e.Referent.Prenom); break; - case "date": + case "dateentretien": epDTOs = epDTOs.OrderBy(e => e.DatePrevisionnelle); break; case "typeep": epDTOs = epDTOs.OrderBy(e => e.Type); break; - case "etatep": + case "statutep": epDTOs = epDTOs.OrderBy(e => e.Statut); break; + case "datearrivee": + epDTOs = epDTOs.OrderBy(e => e.Collaborateur.DateArrivee); + break; + case "datedisponibilite": + epDTOs = epDTOs.OrderBy(e => e.DateDisponibilite); + break; } return epDTOs; }