diff --git a/Webzine.Repository.Contracts/IArtisteRepository.cs b/Webzine.Repository.Contracts/IArtisteRepository.cs
index 1ab6e83..49754b4 100644
--- a/Webzine.Repository.Contracts/IArtisteRepository.cs
+++ b/Webzine.Repository.Contracts/IArtisteRepository.cs
@@ -44,5 +44,12 @@ namespace Webzine.Repository.Contracts
///
/// L'artiste à mettre à jour.
void Update(Artiste artiste);
+
+ ///
+ /// Récupérer une liste d'artiste à partir d'une recherche.
+ ///
+ /// Nom de l'artiste.
+ /// IEnumarble qui contient la chaine de caractere.
+ IEnumerable Search(string nom);
}
}
\ No newline at end of file
diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs
index 2546bc7..f12617c 100644
--- a/Webzine.Repository/DbArtisteRepository.cs
+++ b/Webzine.Repository/DbArtisteRepository.cs
@@ -4,8 +4,6 @@
namespace Webzine.Repository
{
- using System.Data.Common;
-
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@@ -156,5 +154,23 @@ namespace Webzine.Repository
throw;
}
}
+
+ ///
+ public IEnumerable Search(string mot)
+ {
+ try
+ {
+ var artiste = this.context.Artistes
+ .Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
+ .Include(t => t.Titres)
+ .AsNoTracking()
+ .ToList();
+ return artiste;
+ }
+ catch (Exception ex)
+ {
+ throw new Exception("Erreur lors de la recherche d'artiste {error}", ex);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs
index 67ebabf..69021c5 100644
--- a/Webzine.Repository/LocalArtisteRepository.cs
+++ b/Webzine.Repository/LocalArtisteRepository.cs
@@ -85,5 +85,13 @@ namespace Webzine.Repository
{
throw new NotSupportedException("Mode Local");
}
+
+ ///
+ public IEnumerable Search(string mot)
+ {
+ return this.dataStore.Artistes
+ .Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
+ .ToList();
+ }
}
}
\ No newline at end of file
diff --git a/Webzine.WebApplication/Controllers/RechercheController.cs b/Webzine.WebApplication/Controllers/RechercheController.cs
index 061c9d6..729cf64 100644
--- a/Webzine.WebApplication/Controllers/RechercheController.cs
+++ b/Webzine.WebApplication/Controllers/RechercheController.cs
@@ -29,12 +29,9 @@ namespace Webzine.WebApplication.Controllers
{
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
- var titres = this.titreRepository.Search(mot).ToList();
+ var titres = this.titreRepository.Search(mot);
- var artistes = this.artisteRepository
- .FindAll()
- .Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
- .ToList();
+ var artistes = this.artisteRepository.Search(mot);
var vm = new RechercheIndexViewModel
{
diff --git a/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs b/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs
index 7a53090..3132306 100644
--- a/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs
+++ b/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs
@@ -14,11 +14,11 @@ namespace Webzine.WebApplication.ViewModels.Recherche
///
/// Artistes trouves.
///
- public List Artistes { get; set; } = new ();
+ public IEnumerable Artistes { get; set; } = new List();
///
/// Titres trouves.
///
- public List Titres { get; set; } = new ();
+ public IEnumerable Titres { get; set; } = new List();
}
}
\ No newline at end of file