#184 Implémentation des méthodes des repo en local. Suprression des exceptions de non implementation.
This commit is contained in:
@@ -36,21 +36,19 @@ namespace Webzine.Repository
|
||||
/// <inheritdoc/>
|
||||
public void Add(Artiste artiste)
|
||||
{
|
||||
throw new NotSupportedException("Mode Local"); // TODO à implémenter
|
||||
this.dataStore.Artistes.Add(artiste);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Delete(Artiste artiste)
|
||||
{
|
||||
throw new NotSupportedException("Mode Local");
|
||||
this.dataStore.Artistes.Remove(artiste);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Artiste Find(int id)
|
||||
{
|
||||
var artiste = this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id);
|
||||
|
||||
return artiste;
|
||||
return this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -69,7 +67,6 @@ namespace Webzine.Repository
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
|
||||
public IEnumerable<Artiste> FindAll()
|
||||
{
|
||||
return this.dataStore.Artistes;
|
||||
@@ -78,7 +75,16 @@ namespace Webzine.Repository
|
||||
/// <inheritdoc/>
|
||||
public void Update(Artiste artiste)
|
||||
{
|
||||
throw new NotSupportedException("Mode Local");
|
||||
var stored = this.dataStore.Artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
|
||||
if (stored == null)
|
||||
{
|
||||
this.logger.LogWarning("L'artiste {Id} n'a pas été trouvé pour l'update.", artiste.IdArtiste);
|
||||
return;
|
||||
}
|
||||
|
||||
stored.Nom = artiste.Nom;
|
||||
stored.Biographie = artiste.Biographie;
|
||||
stored.Titres = artiste.Titres;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
namespace Webzine.Repository
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -36,13 +35,13 @@ namespace Webzine.Repository
|
||||
/// <inheritdoc/>
|
||||
public void Add(Commentaire commentaire)
|
||||
{
|
||||
throw new NotSupportedException("Mode Local"); // TODO à implémenter
|
||||
this.dataStore.Commentaires.Add(commentaire);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Delete(Commentaire commentaire)
|
||||
{
|
||||
throw new NotSupportedException("Mode Local");
|
||||
this.dataStore.Commentaires.Remove(commentaire);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -31,19 +31,19 @@ public class LocalStyleRepository : IStyleRepository
|
||||
/// <inheritdoc/>
|
||||
public void Add(Style style)
|
||||
{
|
||||
throw new NotSupportedException("Mode local");
|
||||
this.dataStore.Styles.Add(style);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Delete(Style style)
|
||||
{
|
||||
throw new NotSupportedException("Mode local");
|
||||
this.dataStore.Styles.Remove(style);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Style Find(int id)
|
||||
{
|
||||
return this.dataStore.Styles.Find(s => s.IdStyle == id);
|
||||
return this.dataStore.Styles.SingleOrDefault(s => s.IdStyle == id);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -55,6 +55,14 @@ public class LocalStyleRepository : IStyleRepository
|
||||
/// <inheritdoc/>
|
||||
public void Update(Style style)
|
||||
{
|
||||
throw new NotSupportedException("Mode local");
|
||||
var stored = this.dataStore.Styles.FirstOrDefault(s => s.IdStyle == style.IdStyle);
|
||||
if (stored == null)
|
||||
{
|
||||
this.logger.LogWarning("Style with id {IdStyle} not found for update.", style.IdStyle);
|
||||
return;
|
||||
}
|
||||
|
||||
stored.Libelle = style.Libelle;
|
||||
stored.Titres = style.Titres;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class LocalTitreRepository : ITitreRepository
|
||||
/// <inheritdoc/>
|
||||
public void Add(Titre titre)
|
||||
{
|
||||
throw new NotSupportedException("Mode local");
|
||||
this.dataStore.Titres.Add(titre);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -41,7 +41,7 @@ public class LocalTitreRepository : ITitreRepository
|
||||
/// <inheritdoc/>
|
||||
public void Delete(Titre titre)
|
||||
{
|
||||
throw new NotSupportedException("Mode Local");
|
||||
this.dataStore.Titres.Remove(titre);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -115,6 +115,18 @@ public class LocalTitreRepository : ITitreRepository
|
||||
/// <inheritdoc/>
|
||||
public void Update(Titre titre)
|
||||
{
|
||||
throw new NotSupportedException("Mode local");
|
||||
var stored = this.dataStore.Titres.FirstOrDefault(t => t.IdTitre == titre.IdTitre);
|
||||
if (stored == null)
|
||||
{
|
||||
this.logger.LogWarning("Titre avec l'ID {Id} non trouvé pour mise à jour.", titre.IdTitre);
|
||||
return;
|
||||
}
|
||||
|
||||
stored.Libelle = titre.Libelle;
|
||||
stored.DateCreation = titre.DateCreation;
|
||||
stored.NbLectures = titre.NbLectures;
|
||||
stored.NbLikes = titre.NbLikes;
|
||||
stored.IdArtiste = titre.IdArtiste;
|
||||
stored.Styles = titre.Styles;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user