diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs
index 8a4f51c..2824780 100644
--- a/Webzine.Repository/LocalArtisteRepository.cs
+++ b/Webzine.Repository/LocalArtisteRepository.cs
@@ -36,21 +36,19 @@ namespace Webzine.Repository
///
public void Add(Artiste artiste)
{
- throw new NotSupportedException("Mode Local"); // TODO à implémenter
+ this.dataStore.Artistes.Add(artiste);
}
///
public void Delete(Artiste artiste)
{
- throw new NotSupportedException("Mode Local");
+ this.dataStore.Artistes.Remove(artiste);
}
///
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);
}
///
@@ -69,7 +67,6 @@ namespace Webzine.Repository
}
///
- /// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
public IEnumerable FindAll()
{
return this.dataStore.Artistes;
@@ -78,7 +75,16 @@ namespace Webzine.Repository
///
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;
}
///
diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs
index 7096f49..98eea4d 100644
--- a/Webzine.Repository/LocalCommentaireRepository.cs
+++ b/Webzine.Repository/LocalCommentaireRepository.cs
@@ -4,7 +4,6 @@
namespace Webzine.Repository
{
- using System;
using System.Collections.Generic;
using System.Linq;
@@ -36,13 +35,13 @@ namespace Webzine.Repository
///
public void Add(Commentaire commentaire)
{
- throw new NotSupportedException("Mode Local"); // TODO à implémenter
+ this.dataStore.Commentaires.Add(commentaire);
}
///
public void Delete(Commentaire commentaire)
{
- throw new NotSupportedException("Mode Local");
+ this.dataStore.Commentaires.Remove(commentaire);
}
///
diff --git a/Webzine.Repository/LocalStyleRepository.cs b/Webzine.Repository/LocalStyleRepository.cs
index 76d37dc..5bf5979 100644
--- a/Webzine.Repository/LocalStyleRepository.cs
+++ b/Webzine.Repository/LocalStyleRepository.cs
@@ -31,19 +31,19 @@ public class LocalStyleRepository : IStyleRepository
///
public void Add(Style style)
{
- throw new NotSupportedException("Mode local");
+ this.dataStore.Styles.Add(style);
}
///
public void Delete(Style style)
{
- throw new NotSupportedException("Mode local");
+ this.dataStore.Styles.Remove(style);
}
///
public Style Find(int id)
{
- return this.dataStore.Styles.Find(s => s.IdStyle == id);
+ return this.dataStore.Styles.SingleOrDefault(s => s.IdStyle == id);
}
///
@@ -55,6 +55,14 @@ public class LocalStyleRepository : IStyleRepository
///
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;
}
}
\ No newline at end of file
diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs
index 5c5199b..b414a62 100644
--- a/Webzine.Repository/LocalTitreRepository.cs
+++ b/Webzine.Repository/LocalTitreRepository.cs
@@ -28,7 +28,7 @@ public class LocalTitreRepository : ITitreRepository
///
public void Add(Titre titre)
{
- throw new NotSupportedException("Mode local");
+ this.dataStore.Titres.Add(titre);
}
///
@@ -41,7 +41,7 @@ public class LocalTitreRepository : ITitreRepository
///
public void Delete(Titre titre)
{
- throw new NotSupportedException("Mode Local");
+ this.dataStore.Titres.Remove(titre);
}
///
@@ -115,6 +115,18 @@ public class LocalTitreRepository : ITitreRepository
///
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;
}
}
\ No newline at end of file