@ -3,96 +3,93 @@ using System.Collections.Generic;
using System.ComponentModel ;
using System.ComponentModel ;
using System.ComponentModel.Design ;
using System.ComponentModel.Design ;
using System.Linq ;
using System.Linq ;
using System.Runtime.Serialization ;
using System.Text ;
using System.Text ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
namespace Biblioteque_de_Class
namespace Biblioteque_de_Class
{
{
[DataContract]
public class Database
public class Database
{
{
private List < Logo > ListDefaultLogo ;
[DataMember]
private List < Theme > ListTheme ;
private List < Logo > DefaultLogoList ;
private List < Utilisateur > ListUtilisateur ;
[DataMember]
private List < Theme > ThemeList ;
[DataMember]
private List < User > UserList ;
public Database ( )
public Database ( )
{
{
List DefaultLogo = new List < Logo > ( ) ;
DefaultLogoList = new List < Logo > ( ) ;
List Theme = new List < Theme > ( ) ;
ThemeList = new List < Theme > ( ) ;
List Utili sat eu r = new List < U tili sat eu r> ( ) ;
UserList = new List < U ser> ( ) ;
}
}
public List < Logo > Get List DefaultLogo( ) { return List DefaultLogo; }
public List < Logo > Get DefaultLogoList ( ) { return DefaultLogoList ; }
public List < Theme > Get List Theme( ) { return List Theme; }
public List < Theme > Get ThemeList ( ) { return ThemeList ; }
public List < U tili sat eu r> Get ListUtilisateur ( ) { return ListUtilisateur ; }
public List < U ser> Get User List( ) { return User List; }
/// <summary>
/// <summary>
/// recherche un utilisateur dans la liste d'utilisateur
/// recherche un utilisateur dans la liste d'utilisateur
/// </summary>
/// </summary>
public List < U tilisateur> RechercherUtilisateu r( string name )
public List < U ser> SearchUse r( string name )
{
{
List < U tili sat eu r> Li stUserS earch = new List < U tili sat eu r> ( ) ;
List < U ser> searchedUsers = new List < U ser> ( ) ;
string search = name . ToLower ( ) ;
string search = name . ToLower ( ) ;
foreach ( U tilisateur user in ListUtilisateur )
foreach ( U ser user in UserList )
{
{
if ( user . Get Pseudo ( ) . ToLower ( ) . Contains ( search ) ) { Li stUserS earch. Add ( user ) ; }
if ( user . Get Username ( ) . ToLower ( ) . Contains ( search ) ) { searchedUsers . Add ( user ) ; }
}
}
return Li stUserS earch;
return searchedUsers ;
}
}
/// <summary>
/// <summary>
/// récupérer le lien d'un logo
/// récupérer le lien d'un logo
/// </summary>
/// </summary>
public string GetL inkLogo( string N ame)
public string GetL ogoLink( string n ame)
{
{
foreach ( Logo logo in List DefaultLogo)
foreach ( Logo logo in DefaultLogoList )
{
{
if ( logo . GetNom ( ) = = Name ) { return logo . GetNom ( ) ; }
if ( logo . GetName ( ) = = name ) { return logo . GetLogoLink ( ) ; }
} throw new Exception ( "no logo link find" ) ;
}
throw new Exception ( "No logo link found." ) ;
}
}
/// <summary>
/// <summary>
/// récupérer un utilisateur
/// récupérer un utilisateur
/// </summary>
/// </summary>
public Utilisateur GetUtilisateur ( string Name )
public User GetUser ( string name )
{
foreach ( User user in UserList )
{
{
foreach ( Utilisateur user in ListUtilisateur ) {
if ( user . GetUsername ( ) = = name )
if ( user . GetPseudo ( ) = = Name )
{
{
return user ;
return user ;
}
}
} throw new Exception ( "no user find with this pseudo" ) ;
}
throw new Exception ( "No user found with this username." ) ;
}
}
/// <summary>
/// <summary>
/// comparer le mot de passe entré avec celui de l'utilisateur
/// comparer le mot de passe entré avec celui de l'utilisateur
/// </summary>
/// </summary>
public bool Co rrespondPassword( Utilisateur user , string Ps d)
public bool Co mparePassword( User user , string passwor d)
{
{
if ( user . GetPassword ( ) = = Psd )
return user . GetPassword ( ) = = password ;
{
return true ;
}
else
{
return false ;
}
}
}
/// <summary>
/// <summary>
/// rechercher un mail dans la liste d'utilisateur
/// rechercher un mail dans la liste d'utilisateur
/// </summary>
/// </summary>
public bool TrouverMail( string mail)
public bool FindEmail ( string email )
{
{
foreach ( U tilisateur Mail in ListUtilisateur )
foreach ( U ser user in UserList )
{
{
if ( string . Equals ( mail, M ail) )
if ( string . Equals ( user. GetEmail ( ) , em ail) )
{
{
return true ;
return true ;
}
}
else
{
return false ;
}
}
}
return false ;
return false ;
}
}
@ -100,137 +97,115 @@ namespace Biblioteque_de_Class
/// <summary>
/// <summary>
/// ajouter un utilisateur dans la liste d'utilisateur
/// ajouter un utilisateur dans la liste d'utilisateur
/// </summary>
/// </summary>
public void AjouterUtilisateur ( Utilisateur user )
public void AddUser ( User user )
{
foreach ( Utilisateur user1 in ListUtilisateur )
{
{
if ( user1 . GetPseudo ( ) = = user . GetPseudo ( ) )
foreach ( User existingUser in UserList )
{
{
throw new Exception ( "Pseudo déjà utilisé" ) ;
if ( existingUser . GetUsername ( ) = = user . GetUsername ( ) )
}
else if ( user1 . GetMail ( ) = = user . GetMail ( ) )
{
{
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>
/// <summary>
/// supprimer un utilisateur dans la liste d'utilisateur
/// supprimer un utilisateur dans la liste d'utilisateur
/// </summary>
/// </summary>
public void SupUtilisateur( Utilisateu r user )
public void RemoveUser( Use r user )
{
{
foreach ( Utilisateur user1 in ListUtilisateur )
if ( UserList . Contains ( user ) )
{
{
if ( user1 . GetPseudo ( ) = = user . GetPseudo ( ) )
UserList . Remove ( user ) ;
{
ListUtilisateur . Remove ( user ) ;
}
}
else
else
{
{
throw new Exception ( "Utilisateur non trouvé" ) ;
throw new Exception ( "User not found." ) ;
}
}
}
}
}
/// <summary>
/// <summary>
/// ajouter un theme dans la liste de theme
/// ajouter un theme dans la liste de theme
/// </summary>
/// </summary>
public void A jouterTheme( Theme s theme)
public void A ddTheme( Theme theme)
{
{
List < Theme > ListTheme = GetListTheme ( ) ;
foreach ( Theme existingTheme in ThemeList )
foreach ( Theme theme in ListTheme )
{
{
if ( theme . GetNom ( ) = = stheme . GetNom ( ) )
if ( existingTheme . GetName ( ) = = theme . GetName ( ) )
{
throw new Exception ( "Theme déjà utilisé" ) ;
}
else
{
{
ListTheme . Add ( stheme ) ;
throw new Exception ( "Theme already used." ) ;
}
}
}
}
ThemeList . Add ( theme ) ;
}
}
/// <summary>
/// <summary>
/// supprimer un theme dans la liste de theme
/// supprimer un theme dans la liste de theme
/// </summary>
/// </summary>
public void SupTheme ( Theme stheme )
public void RemoveTheme ( Theme theme )
{
List < Theme > ListTheme = GetListTheme ( ) ;
foreach ( Theme theme in ListTheme )
{
{
if ( theme . GetNom ( ) = = stheme . GetNom ( ) )
if ( ThemeList . Contains ( theme ) )
{
{
List Theme. Remove ( theme ) ;
ThemeList . Remove ( theme ) ;
}
}
else
else
{
{
throw new Exception ( "Theme non trouvé" ) ;
throw new Exception ( "Theme not found." ) ;
}
}
}
}
}
/// <summary>
/// <summary>
/// récupérer un theme
/// récupérer un theme
/// </summary>
/// </summary>
public Theme GetTheme ( string N ame)
public Theme GetTheme ( string n ame)
{
{
List < Theme > ListTheme = GetListTheme ( ) ;
foreach ( Theme theme in ThemeList )
foreach ( Theme theme in ListTheme )
{
{
if ( theme . GetN om( ) = = N ame)
if ( theme . GetN ame( ) = = n ame)
{
{
return theme ;
return theme ;
}
}
}
}
throw new Exception ( " no theme find with this name ") ;
throw new Exception ( " No theme found with this name. ") ;
}
}
/// <summary>
/// <summary>
/// modifier le nom d'un theme
/// modifier le nom d'un theme
/// </summary>
/// </summary>
public void ModifierNomTheme ( Theme stheme , string NewName )
public void ModifyThemeName ( Theme theme , string newName )
{
foreach ( Theme theme1 in ListTheme )
{
{
if ( theme1 . GetNom ( ) = = stheme . GetNom ( ) )
foreach ( Theme existingTheme in ThemeList )
{
{
theme1 . SetNom ( NewName ) ;
if ( existingTheme . GetName ( ) = = theme . GetName ( ) )
}
else
{
{
throw new Exception ( "Theme non trouvé" ) ;
existingTheme . SetName ( newName ) ;
return ;
}
}
}
}
throw new Exception ( "Theme not found." ) ;
}
}
/// <summary>
/// <summary>
/// modifier la liste de couleur d'un theme
/// modifier la liste de couleur d'un theme
/// </summary>
/// </summary>
public void Modif ierColorListTheme( Theme stheme , List < string > N ewColorList)
public void Modif yThemeColorList( Theme theme , List < string > n ewColorList)
{
{
foreach ( Theme theme1 in List Theme)
foreach ( Theme exis tingT heme in ThemeList )
{
{
if ( theme1. GetNom ( ) = = stheme . GetNom ( ) )
if ( existingTheme. GetName ( ) = = theme . GetName ( ) )
{
{
for ( int i = 0 ; i < 3 ; i + + )
for ( int i = 0 ; i < 3 ; i + + )
{
{
theme1 . ChangeColor ( theme1 . GetColor ( i ) , N ewColorList[ i ] ) ;
exis tingT heme. ChangeColor ( exis tingT heme. GetColor ( i ) , n ewColorList[ i ] ) ;
}
}
}
return ;
else
{
throw new Exception ( "Theme non trouvé" ) ;
}
}
}
}
throw new Exception ( "Theme not found." ) ;
}
}
}
}
}
}