Files
webzine/Webzine.Repository/LocalCommentaireRepository.cs

73 lines
2.6 KiB
C#

// <copyright file="LocalCommentaireRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using System;
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>
/// Initializes a new instance of the <see cref="LocalCommentaireRepository"/> class.
/// 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)
{
throw new NotSupportedException("Mode Local"); // TODO à implémenter
}
/// <inheritdoc/>
public void Delete(Commentaire commentaire)
{
throw new NotSupportedException("Mode Local");
}
/// <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();
}
}
}