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