From 82255808a95dc6d2799b1848c64d2d30e247bd50 Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Wed, 24 May 2023 11:42:44 +0200 Subject: [PATCH] implementation of a void constructor of user and a copy constructor. Binding between flyoutContainer and MyProfil views --- MCTG/DataPersistence/Stubs.cs | 238 ++++++++++++++--------------- MCTG/Model/Recipes/Review.cs | 3 +- MCTG/Model/User/User.cs | 47 ++++-- MCTG/Views/App.xaml.cs | 7 +- MCTG/Views/ContainerFlyout.xaml | 12 +- MCTG/Views/ContainerFlyout.xaml.cs | 16 +- MCTG/Views/MyProfil.xaml | 15 +- MCTG/Views/MyProfil.xaml.cs | 26 +++- 8 files changed, 199 insertions(+), 165 deletions(-) diff --git a/MCTG/DataPersistence/Stubs.cs b/MCTG/DataPersistence/Stubs.cs index 1539bc5..2b32fec 100644 --- a/MCTG/DataPersistence/Stubs.cs +++ b/MCTG/DataPersistence/Stubs.cs @@ -1,132 +1,132 @@ -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DataPersistence -{ - /// - /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. - /// - public class Stubs : IDataManager - { - public Dictionary> Load() - { - PasswordManager passwordManager = new PasswordManager(); - - Dictionary> data = new Dictionary> - { - { - #region Data: Recipes - nameof(Recipe), - new List(new[] - { - new Recipe( - title: "Cookies classiques", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Faire cuire."), - new PreparationStep(2, "Manger.") - }), - new Recipe( - title: "Cookies au chocolat", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Moulinez la pâte."), - new PreparationStep(2, "Faire cuire pendant une bonne heure."), - new PreparationStep(3, "Sortir du four et mettre dans un plat.") - }), - new Recipe( - title: "Gateau nature", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Achetez les ingrédients."), - new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), - new PreparationStep(3, "Pleurez.") - }), - new Recipe( - title: "Gateau au pommes", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Achetez les légumes."), - new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), - new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), - new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") - }), - new Recipe( - title: "Gateau au chocolat", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Ajouter les oeufs."), - new PreparationStep(2, "Ajouter la farine."), - new PreparationStep(3, "Ajouter 100g de chocolat fondu."), - new PreparationStep(4, "Mélanger le tout."), - new PreparationStep(5, "Faire cuire 45h au four traditionnel.") - }), - new Recipe( - title: "Dinde au jambon", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), - new PreparationStep(2, "Mettre la dinde au frigo."), - new PreparationStep(3, "Mettre le jambon dans le micro-onde."), - new PreparationStep(4, "Faire chauffer 3min."), - new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") - }), - new Recipe( - title: "Poulet au curry", id: null, - preparationSteps: new[] - { - new PreparationStep(1, "Trouvez des épices de curry."), - new PreparationStep(2, "Trouvez maintenant du poulet."), - new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."), - new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), - new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), - new PreparationStep(6, "Dégustez en famille !") - }) - }) - #endregion - }, +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataPersistence +{ + /// + /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. + /// + public class Stubs : IDataManager + { + public Dictionary> Load() + { + + Dictionary> data = new Dictionary> + { { - #region Data: User - nameof(User), + #region Data: Recipes + nameof(Recipe), + new List(new[] + { + new Recipe( + title: "Cookies classiques", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Faire cuire."), + new PreparationStep(2, "Manger.") + }), + new Recipe( + title: "Cookies au chocolat", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Moulinez la pâte."), + new PreparationStep(2, "Faire cuire pendant une bonne heure."), + new PreparationStep(3, "Sortir du four et mettre dans un plat.") + }), + new Recipe( + title: "Gateau nature", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Achetez les ingrédients."), + new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), + new PreparationStep(3, "Pleurez.") + }), + new Recipe( + title: "Gateau au pommes", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Achetez les légumes."), + new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), + new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), + new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") + }), + new Recipe( + title: "Gateau au chocolat", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Ajouter les oeufs."), + new PreparationStep(2, "Ajouter la farine."), + new PreparationStep(3, "Ajouter 100g de chocolat fondu."), + new PreparationStep(4, "Mélanger le tout."), + new PreparationStep(5, "Faire cuire 45h au four traditionnel.") + }), + new Recipe( + title: "Dinde au jambon", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), + new PreparationStep(2, "Mettre la dinde au frigo."), + new PreparationStep(3, "Mettre le jambon dans le micro-onde."), + new PreparationStep(4, "Faire chauffer 3min."), + new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") + }), + new Recipe( + title: "Poulet au curry", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Trouvez des épices de curry."), + new PreparationStep(2, "Trouvez maintenant du poulet."), + new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."), + new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), + new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), + new PreparationStep(6, "Dégustez en famille !") + }) + }) + #endregion + }, + { + #region Data: User + nameof(User), new List(new[] { new User( name: "Admin", surname: "Admin", mail: "admin@mctg.fr", - password: passwordManager.HashPassword("admin")), + password: "admin"), new User( name: "Pedros", surname: "Amigos", mail: "pedrosamigos@hotmail.com", - password: passwordManager.HashPassword("pamigos")) + password: "pamigos") + }) #endregion - } - }; - - return data; - } - - #region Not supported methods - public void Save(Dictionary> elements) - { - throw new NotSupportedException(); - } - - public void Export(T obj, string pathToExport) where T : class - { - throw new NotSupportedException(); - } - - public KeyValuePair Import(string pathToImport) where T : class - { - throw new NotSupportedException(); - } - #endregion - } -} + } + }; + + return data; + } + + #region Not supported methods + public void Save(Dictionary> elements) + { + throw new NotSupportedException(); + } + + public void Export(T obj, string pathToExport) where T : class + { + throw new NotSupportedException(); + } + + public KeyValuePair Import(string pathToImport) where T : class + { + throw new NotSupportedException(); + } + #endregion + } +} diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs index b98d498..d560d23 100644 --- a/MCTG/Model/Recipes/Review.cs +++ b/MCTG/Model/Recipes/Review.cs @@ -66,8 +66,7 @@ namespace Model } public Review(int stars, string content) - : this(new User("admin", "admin", "admin@mctg.fr", new PasswordManager().HashPassword("admin")), - null, stars, content) + : this(new User(), null, stars, content) { } diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index cbcb5e5..d8e4e09 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -17,7 +17,7 @@ namespace Model /// This user can login with an Id and a password /// [DataContract(Name = "user")] - public class User : IEquatable , INotifyPropertyChanged + public class User : IEquatable , INotifyPropertyChanged { #region Private Attributes @@ -40,12 +40,9 @@ namespace Model public string Name { get { return name; } - private set + set { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); - } + name = value; OnPropertyChanged(); } @@ -58,12 +55,9 @@ namespace Model public string Surname { get { return surname; } - private set + set { - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); - } + surname = value; OnPropertyChanged(); } @@ -147,7 +141,7 @@ namespace Model return $"{Name} {Surname}"; } - + public IPasswordManager psswMgr { get; private set; } #endregion @@ -161,12 +155,13 @@ namespace Model /// The name of the user /// The surname of the user /// The user needs an email to login. - public User(string name, string surname, string mail, int password) + public User(string name, string surname, string mail, string password, IPasswordManager passwordManager ) { Name = name; Surname = surname; Mail = mail; - Password = password; + psswMgr = passwordManager; + Password = psswMgr.HashPassword(password); priorities = new List { Priority.Gourmet, Priority.Economic, @@ -176,8 +171,30 @@ namespace Model ProfilPict = picture; } + public User(string name, string surname, string mail, string password) + : this(name, surname,mail, password, new PasswordManager()) + { + + } + + + public User() + : this("John", "Doe", "truc@gmail.com", "mdp") + { + + } + + public User (User user) + { + Name = user.Name; + Surname = user.Surname; + Mail = user.Mail; + psswMgr = user.psswMgr; + Password = user.Password; + priorities = user.Priorities; + ProfilPict = user.ProfilPict; + } - #endregion diff --git a/MCTG/Views/App.xaml.cs b/MCTG/Views/App.xaml.cs index 59c681f..0ae3fef 100644 --- a/MCTG/Views/App.xaml.cs +++ b/MCTG/Views/App.xaml.cs @@ -5,17 +5,20 @@ using Windows.Graphics; #endif using DataPersistence; - +using Model; + namespace Views { public partial class App : Application { public DataManager DataMgr { get; private set; } = new DataManager(new Stubs()); + public User user { get; set; } const int WindowWidth = 1200; const int WindowHeight = 800; public App() - { + { + user = DataMgr.Data[nameof(User)].Cast().Last(); InitializeComponent(); Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => diff --git a/MCTG/Views/ContainerFlyout.xaml b/MCTG/Views/ContainerFlyout.xaml index 0001b22..07193e3 100644 --- a/MCTG/Views/ContainerFlyout.xaml +++ b/MCTG/Views/ContainerFlyout.xaml @@ -28,11 +28,19 @@ Style="{StaticResource button2}" IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}" IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"/> -