98 lines
3.3 KiB
C#
98 lines
3.3 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.
|
|
/// Utilise <see cref="ICommentaireRepository"/> en injection de dépendances.
|
|
/// </summary>
|
|
public class LocalCommentaireRepository : ICommentaireRepository
|
|
{
|
|
private readonly ILogger<LocalCommentaireRepository> logger;
|
|
private readonly InMemoryDataStore dataStore;
|
|
|
|
/// <summary>
|
|
/// Initialise une nouvelle instance du <see cref="LocalCommentaireRepository"/> .
|
|
/// Est liée à un magasin de données en mémoire et utilise un logger pour enregistrer les opérations.
|
|
/// </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");
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Delete(Commentaire commentaire)
|
|
{
|
|
throw new NotSupportedException("Mode Local");
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public int Count()
|
|
{
|
|
return this.dataStore.Commentaires.Count;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public Commentaire Find(int idCommentaire)
|
|
{
|
|
|
|
var commentaire = this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire);
|
|
if (commentaire == null)
|
|
{
|
|
return new Commentaire();
|
|
}
|
|
|
|
return commentaire;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IEnumerable<Commentaire> FindAll()
|
|
{
|
|
return this.dataStore.Commentaires
|
|
.OrderByDescending(c => c.DateCreation)
|
|
.ToList();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IEnumerable<Commentaire> FindCommentaires(int offset, int limit)
|
|
{
|
|
if (offset < 0 || limit <= 0)
|
|
{
|
|
return Enumerable.Empty<Commentaire>();
|
|
}
|
|
|
|
return this.dataStore.Commentaires
|
|
.OrderByDescending(c => c.DateCreation)
|
|
.Skip(offset)
|
|
.Take(limit)
|
|
.ToList();
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IEnumerable<Commentaire> FindByIdTitre(int idTitre)
|
|
{
|
|
return this.dataStore.Commentaires
|
|
.Where(c => c.Titre != null && c.Titre.IdTitre == idTitre)
|
|
.OrderByDescending(c => c.DateCreation)
|
|
.ToList();
|
|
}
|
|
}
|
|
} |