// // Copyright (c) PlaceholderCompany. All rights reserved. // namespace Webzine.Repository { using System; 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. /// Utilise en injection de dépendances. /// public class LocalCommentaireRepository : ICommentaireRepository { private readonly ILogger logger; private readonly InMemoryDataStore dataStore; /// /// Initializes a new instance of the class. /// Initialise une nouvelle instance du . /// Est liée à un magasin de données en mémoire et utilise un logger pour enregistrer les opérations. /// /// 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) { throw new NotSupportedException("Mode Local"); // TODO à implémenter } /// public void Delete(Commentaire commentaire) { throw new NotSupportedException("Mode Local"); } /// public int Count() { return this.dataStore.Commentaires.Count; } /// public Commentaire Find(int idCommentaire) { var commentaire = this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire); if (commentaire == null) { return new Commentaire(); } return commentaire; } /// public IEnumerable FindAll() { return this.dataStore.Commentaires .OrderByDescending(c => c.DateCreation) .ToList(); } /// public IEnumerable FindCommentaires(int offset, int limit) { if (offset < 0 || limit <= 0) { return Enumerable.Empty(); } return this.dataStore.Commentaires .OrderByDescending(c => c.DateCreation) .Skip(offset) .Take(limit) .ToList(); } /// public IEnumerable FindByIdTitre(int idTitre) { return this.dataStore.Commentaires .Where(c => c.Titre != null && c.Titre.IdTitre == idTitre) .OrderByDescending(c => c.DateCreation) .ToList(); } } }