74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
namespace Webzine.Repository;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Webzine.Entity;
|
|
using Webzine.Repository.Contracts;
|
|
|
|
/// <summary>
|
|
/// Classe qui implémente le repository pour les styles en utilisant une liste locale comme source de données.
|
|
/// </summary>
|
|
public class LocalStyleRepository : IStyleRepository
|
|
{
|
|
private readonly ILogger<LocalStyleRepository> logger;
|
|
|
|
// private readonly List<Style> styles;
|
|
private readonly InMemoryDataStore dataStore;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="LocalStyleRepository"/> class.
|
|
/// Gère les opérations liées aux styles en utilisant une source de données locale (en mémoire).
|
|
/// </summary>
|
|
/// <param name="logger">Le service de journalisation injecté pour suivre les opérations du repository.</param>
|
|
/// <param name="dataStore">Les données en mémoire.</param>
|
|
public LocalStyleRepository(ILogger<LocalStyleRepository> logger, InMemoryDataStore dataStore)
|
|
{
|
|
this.logger = logger;
|
|
this.dataStore = dataStore;
|
|
this.logger.LogDebug(1, "NLog injecté dans LocalStyleRepository");
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Add(Style style)
|
|
{
|
|
this.dataStore.Styles.Add(style);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Delete(Style style)
|
|
{
|
|
this.dataStore.Styles.Remove(style);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public Style Find(int id)
|
|
{
|
|
return this.dataStore.Styles.SingleOrDefault(s => s.IdStyle == id);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IEnumerable<Style> FindAll()
|
|
{
|
|
return this.dataStore.Styles.ToList();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Update(Style style)
|
|
{
|
|
var stored = this.dataStore.Styles.FirstOrDefault(s => s.IdStyle == style.IdStyle);
|
|
if (stored == null)
|
|
{
|
|
this.logger.LogWarning("Style with id {IdStyle} not found for update.", style.IdStyle);
|
|
return;
|
|
}
|
|
|
|
stored.Libelle = style.Libelle;
|
|
stored.Titres = style.Titres;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public int Count()
|
|
{
|
|
return this.dataStore.Styles.Count;
|
|
}
|
|
} |