|
|
|
@ -8,14 +8,13 @@ using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace MangaMap.Stub
|
|
|
|
|
{
|
|
|
|
|
public class DataContract : IPersistanceManager
|
|
|
|
|
{
|
|
|
|
|
public string FileName { get; set; } = "SauvegardeDonnees.xml";
|
|
|
|
|
public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
|
|
|
|
|
//public string FilePath2 { get; set; } = "C:\\Users\\vjour\\UCA\\MapManga\\MangaMap";
|
|
|
|
|
//public string FilePath2 { get; set; } = Path.Combine(Directory.GetCurrentDirectory(), "\\..\\..\\Users");
|
|
|
|
|
|
|
|
|
|
public (List<Oeuvre>, List<Utilisateur>) chargeDonne()
|
|
|
|
|
{
|
|
|
|
@ -24,13 +23,11 @@ namespace MangaMap.Stub
|
|
|
|
|
|
|
|
|
|
if (File.Exists(Path.Combine(FilePath, FileName))) // Vérifiez si le fichier existe
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName)))
|
|
|
|
|
{
|
|
|
|
|
data = serializer.ReadObject(s) as DataToPersist;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data = new DataToPersist(); // Si le fichier n'existe pas, créez une nouvelle liste
|
|
|
|
@ -56,8 +53,20 @@ namespace MangaMap.Stub
|
|
|
|
|
data = new DataToPersist();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Vérifier si un utilisateur avec le même nom d'utilisateur existe déjà
|
|
|
|
|
var existingUser = data.Utilisateurs.FirstOrDefault(user => user.Pseudo == u.Last().Pseudo);
|
|
|
|
|
if (existingUser != null)
|
|
|
|
|
{
|
|
|
|
|
// Mettre à jour l'utilisateur existant
|
|
|
|
|
existingUser.MotDePasse = u.Last().MotDePasse;
|
|
|
|
|
existingUser.Email = u.Last().Email;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Ajouter le nouvel utilisateur à la liste existante
|
|
|
|
|
data.Utilisateurs.Add(u.Last());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName)))
|
|
|
|
@ -68,6 +77,6 @@ namespace MangaMap.Stub
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|