Ajout du moteur de recherche dans le header
This commit is contained in:
@@ -1,18 +1,71 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.Repository.Contracts;
|
||||
|
||||
namespace Webzine.Repository;
|
||||
|
||||
public class LocalEntityRepository
|
||||
/// <summary>
|
||||
/// Classe qui permet d'initialiser un jeu de données
|
||||
/// pour tester l'application
|
||||
/// </summary>
|
||||
public class LocalEntityRepository : ITitreRepository
|
||||
{
|
||||
private readonly ILogger<LocalEntityRepository> _logger;
|
||||
private readonly List<Titre> _titres;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise une nouvelle instance du <see cref="LocalEntityRepository"/> avec un service de journalisation injecté.
|
||||
/// Initialise une nouvelle instance du <see cref="LocalEntityRepository"/> avec un service de journalisation injecte.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté pour suivre les opérations du repository.</param>
|
||||
/// <param name="logger">Service de journalisation injecte pour suivre les operations du repository.</param>
|
||||
public LocalEntityRepository(ILogger<LocalEntityRepository> logger)
|
||||
{
|
||||
this._logger = logger;
|
||||
this._logger.LogDebug(1, "NLog injected into LocalEntityRepository");
|
||||
_logger = logger;
|
||||
_logger.LogDebug(1, "NLog injected into LocalEntityRepository");
|
||||
|
||||
var factory = new DataFactory();
|
||||
var artistes = factory.GenerateArtists(10);
|
||||
var styles = factory.GenerateStyles(10);
|
||||
|
||||
_titres = factory.GenerateTitres(30, artistes, styles);
|
||||
factory.GenerateCommentaires(50, _titres);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Titre> Search(string mot)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mot))
|
||||
{
|
||||
return Enumerable.Empty<Titre>();
|
||||
}
|
||||
|
||||
return _titres
|
||||
.Where(t => !string.IsNullOrWhiteSpace(t.Libelle)
|
||||
&& t.Libelle.Contains(mot, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(t => t.Libelle)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Titre? Find(int idTitre)
|
||||
{
|
||||
return _titres.FirstOrDefault(t => t.IdTitre == idTitre);
|
||||
}
|
||||
|
||||
public IEnumerable<Titre> FindAll()
|
||||
{
|
||||
return _titres;
|
||||
}
|
||||
|
||||
public IEnumerable<Titre> SearchByStyle(string libelle)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(libelle))
|
||||
{
|
||||
return Enumerable.Empty<Titre>();
|
||||
}
|
||||
|
||||
return _titres
|
||||
.Where(t => t.Styles.Any(s => !string.IsNullOrWhiteSpace(s.Libelle)
|
||||
&& s.Libelle.Contains(libelle, StringComparison.OrdinalIgnoreCase)))
|
||||
.OrderBy(t => t.Libelle)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Webzine.Entity\Webzine.Entity.csproj" />
|
||||
<ProjectReference Include="..\Webzine.Repository.Contracts\Webzine.Repository.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user