|
|
|
@ -10,89 +10,81 @@ namespace Biblioteque_de_Class
|
|
|
|
|
{
|
|
|
|
|
public class Database
|
|
|
|
|
{
|
|
|
|
|
private List<Logo> ListDefaultLogo;
|
|
|
|
|
private List<Theme> ListTheme;
|
|
|
|
|
private List<Utilisateur> ListUtilisateur;
|
|
|
|
|
private List<Logo> DefaultLogoList;
|
|
|
|
|
private List<Theme> ThemeList;
|
|
|
|
|
private List<User> UserList;
|
|
|
|
|
|
|
|
|
|
public Database()
|
|
|
|
|
{
|
|
|
|
|
ListDefaultLogo = new List<Logo>();
|
|
|
|
|
ListTheme = new List<Theme>();
|
|
|
|
|
ListUtilisateur = new List<Utilisateur>();
|
|
|
|
|
public Database()
|
|
|
|
|
{
|
|
|
|
|
DefaultLogoList = new List<Logo>();
|
|
|
|
|
ThemeList = new List<Theme>();
|
|
|
|
|
UserList = new List<User>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Logo> GetListDefaultLogo() { return ListDefaultLogo; }
|
|
|
|
|
public List<Theme> GetListTheme() { return ListTheme; }
|
|
|
|
|
public List<Utilisateur> GetListUtilisateur() { return ListUtilisateur; }
|
|
|
|
|
public List<Logo> GetDefaultLogoList() { return DefaultLogoList; }
|
|
|
|
|
public List<Theme> GetThemeList() { return ThemeList; }
|
|
|
|
|
public List<User> GetUserList() { return UserList; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// recherche un utilisateur dans la liste d'utilisateur
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<Utilisateur> RechercherUtilisateur(string name)
|
|
|
|
|
public List<User> SearchUser(string name)
|
|
|
|
|
{
|
|
|
|
|
List<Utilisateur> ListUserSearch = new List<Utilisateur>();
|
|
|
|
|
List<User> searchedUsers = new List<User>();
|
|
|
|
|
string search = name.ToLower();
|
|
|
|
|
foreach (Utilisateur user in ListUtilisateur)
|
|
|
|
|
foreach (User user in UserList)
|
|
|
|
|
{
|
|
|
|
|
if (user.GetPseudo().ToLower().Contains(search)) { ListUserSearch.Add(user); }
|
|
|
|
|
if (user.GetUsername().ToLower().Contains(search)) { searchedUsers.Add(user); }
|
|
|
|
|
}
|
|
|
|
|
return ListUserSearch;
|
|
|
|
|
return searchedUsers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// récupérer le lien d'un logo
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string GetLinkLogo(string Name)
|
|
|
|
|
public string GetLogoLink(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (Logo logo in ListDefaultLogo)
|
|
|
|
|
foreach (Logo logo in DefaultLogoList)
|
|
|
|
|
{
|
|
|
|
|
if (logo.GetNom() == Name) { return logo.GetNom(); }
|
|
|
|
|
}throw new Exception("no logo link find");
|
|
|
|
|
if (logo.GetName() == name) { return logo.GetLink(); }
|
|
|
|
|
}
|
|
|
|
|
throw new Exception("No logo link found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// récupérer un utilisateur
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Utilisateur GetUtilisateur(string Name)
|
|
|
|
|
{
|
|
|
|
|
foreach(Utilisateur user in ListUtilisateur){
|
|
|
|
|
if(user.GetPseudo() == Name)
|
|
|
|
|
public User GetUser(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (User user in UserList)
|
|
|
|
|
{
|
|
|
|
|
if (user.GetUsername() == name)
|
|
|
|
|
{
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
}throw new Exception("no user find with this pseudo");
|
|
|
|
|
}
|
|
|
|
|
throw new Exception("No user found with this username.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// comparer le mot de passe entré avec celui de l'utilisateur
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool CorrespondPassword(Utilisateur user, string Psd)
|
|
|
|
|
public bool ComparePassword(User user, string password)
|
|
|
|
|
{
|
|
|
|
|
if (user.GetPassword() == Psd)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return user.GetPassword() == password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// rechercher un mail dans la liste d'utilisateur
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool TrouverMail(string mail)
|
|
|
|
|
public bool FindEmail(string email)
|
|
|
|
|
{
|
|
|
|
|
foreach (Utilisateur Mail in ListUtilisateur)
|
|
|
|
|
foreach (User user in UserList)
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(mail,Mail))
|
|
|
|
|
if (string.Equals(user.GetEmail(), email))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -100,137 +92,115 @@ namespace Biblioteque_de_Class
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ajouter un utilisateur dans la liste d'utilisateur
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void AjouterUtilisateur(Utilisateur user)
|
|
|
|
|
public void AddUser(User user)
|
|
|
|
|
{
|
|
|
|
|
foreach (Utilisateur user1 in ListUtilisateur)
|
|
|
|
|
foreach (User existingUser in UserList)
|
|
|
|
|
{
|
|
|
|
|
if (user1.GetPseudo() == user.GetPseudo())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Pseudo déjà utilisé");
|
|
|
|
|
}
|
|
|
|
|
else if (user1.GetMail() == user.GetMail())
|
|
|
|
|
if (existingUser.GetUsername() == user.GetUsername())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Mail déjà utilisé");
|
|
|
|
|
throw new Exception("Username already used.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else if (existingUser.GetEmail() == user.GetEmail())
|
|
|
|
|
{
|
|
|
|
|
ListUtilisateur.Add(user);
|
|
|
|
|
throw new Exception("Email already used.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UserList.Add(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// supprimer un utilisateur dans la liste d'utilisateur
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SupUtilisateur(Utilisateur user)
|
|
|
|
|
public void RemoveUser(User user)
|
|
|
|
|
{
|
|
|
|
|
foreach (Utilisateur user1 in ListUtilisateur)
|
|
|
|
|
if (UserList.Contains(user))
|
|
|
|
|
{
|
|
|
|
|
if (user1.GetPseudo() == user.GetPseudo())
|
|
|
|
|
{
|
|
|
|
|
ListUtilisateur.Remove(user);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Utilisateur non trouvé");
|
|
|
|
|
}
|
|
|
|
|
UserList.Remove(user);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("User not found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ajouter un theme dans la liste de theme
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void AjouterTheme(Theme stheme)
|
|
|
|
|
public void AddTheme(Theme theme)
|
|
|
|
|
{
|
|
|
|
|
List<Theme> ListTheme = GetListTheme();
|
|
|
|
|
foreach (Theme theme in ListTheme)
|
|
|
|
|
foreach (Theme existingTheme in ThemeList)
|
|
|
|
|
{
|
|
|
|
|
if (theme.GetNom() == stheme.GetNom())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Theme déjà utilisé");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (existingTheme.GetName() == theme.GetName())
|
|
|
|
|
{
|
|
|
|
|
ListTheme.Add(stheme);
|
|
|
|
|
throw new Exception("Theme already used.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ThemeList.Add(theme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// supprimer un theme dans la liste de theme
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SupTheme(Theme stheme)
|
|
|
|
|
public void RemoveTheme(Theme theme)
|
|
|
|
|
{
|
|
|
|
|
List<Theme> ListTheme = GetListTheme();
|
|
|
|
|
foreach (Theme theme in ListTheme)
|
|
|
|
|
if (ThemeList.Contains(theme))
|
|
|
|
|
{
|
|
|
|
|
if (theme.GetNom() == stheme.GetNom())
|
|
|
|
|
{
|
|
|
|
|
ListTheme.Remove(theme);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Theme non trouvé");
|
|
|
|
|
}
|
|
|
|
|
ThemeList.Remove(theme);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Theme not found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// récupérer un theme
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Theme GetTheme(string Name)
|
|
|
|
|
public Theme GetTheme(string name)
|
|
|
|
|
{
|
|
|
|
|
List<Theme> ListTheme = GetListTheme();
|
|
|
|
|
foreach (Theme theme in ListTheme)
|
|
|
|
|
foreach (Theme theme in ThemeList)
|
|
|
|
|
{
|
|
|
|
|
if (theme.GetNom() == Name)
|
|
|
|
|
if (theme.GetName() == name)
|
|
|
|
|
{
|
|
|
|
|
return theme;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new Exception("no theme find with this name");
|
|
|
|
|
throw new Exception("No theme found with this name.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// modifier le nom d'un theme
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ModifierNomTheme( Theme stheme, string NewName)
|
|
|
|
|
public void ModifyThemeName(Theme theme, string newName)
|
|
|
|
|
{
|
|
|
|
|
foreach (Theme theme1 in ListTheme)
|
|
|
|
|
foreach (Theme existingTheme in ThemeList)
|
|
|
|
|
{
|
|
|
|
|
if (theme1.GetNom() == stheme.GetNom())
|
|
|
|
|
{
|
|
|
|
|
theme1.SetNom(NewName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (existingTheme.GetName() == theme.GetName())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Theme non trouvé");
|
|
|
|
|
existingTheme.SetName(newName);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new Exception("Theme not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// modifier la liste de couleur d'un theme
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ModifierColorListTheme(Theme stheme, List<string> NewColorList)
|
|
|
|
|
public void ModifyThemeColorList(Theme theme, List<string> newColorList)
|
|
|
|
|
{
|
|
|
|
|
foreach (Theme theme1 in ListTheme)
|
|
|
|
|
foreach (Theme existingTheme in ThemeList)
|
|
|
|
|
{
|
|
|
|
|
if (theme1.GetNom() == stheme.GetNom())
|
|
|
|
|
if (existingTheme.GetName() == theme.GetName())
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
theme1.ChangeColor(theme1.GetColor(i), NewColorList[i]);
|
|
|
|
|
existingTheme.ChangeColor(existingTheme.GetColor(i), newColorList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Theme non trouvé");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new Exception("Theme not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|