diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index 404f7bf..2546bc7 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -120,7 +120,7 @@ namespace Webzine.Repository try { // .AsNoTracking() rend la requête beaucoup plus rapide pour de la lecture - var artistes = this.context.Artistes.AsNoTracking().ToList(); + var artistes = this.context.Artistes.AsNoTracking().Include(t => t.Titres).ToList(); this.logger.LogDebug("{Count} artistes récupérés de la base.", artistes.Count); return artistes; } diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index 20b90fd..66ebec5 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -242,6 +242,7 @@ public class DbTitreRepository : ITitreRepository .Include(t => t.Styles) .Where(t => t.Libelle.ToLower().Contains(mot.ToLower())) .OrderBy(t => t.Libelle) + .AsNoTracking() .ToList(); this.logger.LogDebug("{Count} titres trouvés correspondant à '{Mot}'", titres.Count, mot); diff --git a/Webzine.WebApplication/Controllers/RechercheController.cs b/Webzine.WebApplication/Controllers/RechercheController.cs index 9d6f7e2..061c9d6 100644 --- a/Webzine.WebApplication/Controllers/RechercheController.cs +++ b/Webzine.WebApplication/Controllers/RechercheController.cs @@ -8,52 +8,32 @@ namespace Webzine.WebApplication.Controllers using Webzine.Repository.Contracts; using Webzine.WebApplication.ViewModels.Recherche; - using Webzine.WebApplication.ViewModels.Titre; - [Route("recherche")] public class RechercheController : Controller { private readonly ILogger logger; private readonly ITitreRepository titreRepository; + private readonly IArtisteRepository artisteRepository; - public RechercheController(ILogger logger, ITitreRepository titreRepository) + public RechercheController( + ILogger logger, + ITitreRepository titreRepository, + IArtisteRepository artisteRepository) { this.logger = logger; this.titreRepository = titreRepository; + this.artisteRepository = artisteRepository; } - [HttpPost("")] public IActionResult Index(string mot) { this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot); - var titres = this.titreRepository.Search(mot) - .Concat(this.titreRepository.SearchByStyle(mot)) - .DistinctBy(t => t.IdTitre) - .OrderBy(t => t.Libelle) - .Select(t => new TitreStyleItem - { - IdTitre = t.IdTitre, - Libelle = t.Libelle, - ArtisteNom = t.Artiste?.Nom, - UrlJaquette = t.UrlJaquette, - Duree = t.Duree, - }) - .ToList(); + var titres = this.titreRepository.Search(mot).ToList(); - var artistes = this.titreRepository.FindAll() - .Select(t => t.Artiste) - .Where(a => a != null - && !string.IsNullOrWhiteSpace(a.Nom) - && !string.IsNullOrWhiteSpace(mot) - && a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase)) - .DistinctBy(a => a!.IdArtiste) - .OrderBy(a => a!.Nom) - .Select(a => new RechercheArtisteItem - { - Nom = a!.Nom, - NombreDeTitres = a.Titres?.Count ?? 0, - }) + var artistes = this.artisteRepository + .FindAll() + .Where(a => a.Nom.ToLower().Contains(mot.ToLower())) .ToList(); var vm = new RechercheIndexViewModel diff --git a/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs b/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs index 177125d..7a53090 100644 --- a/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs +++ b/Webzine.WebApplication/ViewModels/Recherche/RechercheIndexViewModel.cs @@ -1,24 +1,24 @@ -using Webzine.WebApplication.ViewModels.Titre; - -namespace Webzine.WebApplication.ViewModels.Recherche; - -/// -/// ViewModel pour afficher les resultats de recherche d'artistes et de titres. -/// -public class RechercheIndexViewModel +namespace Webzine.WebApplication.ViewModels.Recherche { + using Webzine.Entity; /// - /// Mot saisi dans le formulaire. + /// ViewModel pour afficher les resultats de recherche d'artistes et de titres. /// - public string? Mot { get; set; } + public class RechercheIndexViewModel + { + /// + /// Mot saisi dans le formulaire. + /// + public string? Mot { get; set; } - /// - /// Artistes trouves. - /// - public List Artistes { get; set; } = new (); + /// + /// Artistes trouves. + /// + public List Artistes { get; set; } = new (); - /// - /// Titres trouves. - /// - public List Titres { get; set; } = new (); + /// + /// Titres trouves. + /// + public List Titres { get; set; } = new (); + } } \ No newline at end of file diff --git a/Webzine.WebApplication/Views/Recherche/Index.cshtml b/Webzine.WebApplication/Views/Recherche/Index.cshtml index cb5fca6..53e3853 100644 --- a/Webzine.WebApplication/Views/Recherche/Index.cshtml +++ b/Webzine.WebApplication/Views/Recherche/Index.cshtml @@ -10,74 +10,65 @@

Resultats pour "@Model.Mot"


+

Artistes

- @if (string.IsNullOrWhiteSpace(Model.Mot)) + @if (!Model.Artistes.Any()) {
- Saisissez un mot-cle pour lancer une recherche. +

Aucun artiste n'a été trouvé.

} - else if (!Model.Artistes.Any() && !Model.Titres.Any()) + + @foreach (var artiste in Model.Artistes) + { +
+ + @artiste.Nom + + (@artiste.Titres.Count titre(s)) +
+ } +

Titres

+ + @if (!Model.Titres.Any()) {
- Aucun artiste ni titre ne correspond a votre recherche. +

Aucun titre n'a été trouvé.

} - else - { - @if (Model.Artistes.Any()) - { -

Artistes

- @foreach (var artiste in Model.Artistes) - { -
+ @foreach (var titre in Model.Titres) + { +
+ + @titre.Libelle + + +
+ - } - } - - @if (Model.Titres.Any()) - { -

Titres

- - @foreach (var titre in Model.Titres) - { -
+ - - @titre.Libelle + asp-route-id="@titre.IdTitre"> + @titre.Libelle - -
- - -
- Duree : @TimeSpan.FromSeconds(titre.Duree).ToString(@"mm\:ss") -
-
- } - } + +
+ Duree : @TimeSpan.FromSeconds(titre.Duree).ToString(@"mm\:ss") +
+
+
}
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css deleted file mode 100644 index e69de29..0000000