71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
// <copyright file="LocalCommentaireRepository.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace Webzine.Repository
|
|
{
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Webzine.Entity;
|
|
using Webzine.Repository.Contracts;
|
|
|
|
/// <summary>
|
|
/// Initialise une classe <see cref="LocalCommentaireRepository"/> qui implémente l'interface <see cref="ICommentaireRepository"/> pour gérer les opérations liées aux commentaires.
|
|
/// </summary>
|
|
public class LocalCommentaireRepository : ICommentaireRepository
|
|
{
|
|
private readonly ILogger<LocalCommentaireRepository> logger;
|
|
private readonly InMemoryDataStore dataStore;
|
|
|
|
/// <summary>
|
|
/// Initialise une nouvelle instance du <see cref="LocalCommentaireRepository"/> .
|
|
/// Gère les opérations liées aux commentaires en utilisant une source de données locale (en mémoire).
|
|
/// </summary>
|
|
/// <param name="dataStore">Le magasin de données en mémoire. Ne peut pas être null.</param>
|
|
/// <param name="logger">Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null.</param>
|
|
public LocalCommentaireRepository(InMemoryDataStore dataStore, ILogger<LocalCommentaireRepository> logger)
|
|
{
|
|
this.logger = logger;
|
|
this.dataStore = dataStore;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Add(Commentaire commentaire)
|
|
{
|
|
this.dataStore.Commentaires.Add(commentaire);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Delete(Commentaire commentaire)
|
|
{
|
|
this.dataStore.Commentaires.Remove(commentaire);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public Commentaire Find(int idCommentaire)
|
|
{
|
|
return this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IEnumerable<Commentaire> FindAll()
|
|
{
|
|
return this.dataStore.Commentaires
|
|
.OrderByDescending(c => c.DateCreation)
|
|
.ToList();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IEnumerable<Commentaire> Paginate(int offset, int limit)
|
|
{
|
|
return this.dataStore.Commentaires
|
|
.OrderByDescending(c => c.DateCreation)
|
|
.Skip(offset)
|
|
.Take(limit)
|
|
.ToList();
|
|
}
|
|
}
|
|
} |