implementation of a void constructor of user and a copy constructor. Binding between flyoutContainer and MyProfil views
continuous-integration/drone/push Build is failing Details

pull/48/head
Roxane ROSSETTO 2 years ago
parent 5a255642b5
commit 82255808a9

@ -1,132 +1,132 @@
using Model; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DataPersistence namespace DataPersistence
{ {
/// <summary> /// <summary>
/// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing.
/// </summary> /// </summary>
public class Stubs : IDataManager public class Stubs : IDataManager
{ {
public Dictionary<string, List<object>> Load() public Dictionary<string, List<object>> Load()
{ {
PasswordManager passwordManager = new PasswordManager();
Dictionary<string, List<object>> data = new Dictionary<string, List<object>>
Dictionary<string, List<object>> data = new Dictionary<string, List<object>> {
{
{
#region Data: Recipes
nameof(Recipe),
new List<object>(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 #region Data: Recipes
nameof(User), nameof(Recipe),
new List<object>(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<object>(new[] new List<object>(new[]
{ {
new User( new User(
name: "Admin", name: "Admin",
surname: "Admin", surname: "Admin",
mail: "admin@mctg.fr", mail: "admin@mctg.fr",
password: passwordManager.HashPassword("admin")), password: "admin"),
new User( new User(
name: "Pedros", name: "Pedros",
surname: "Amigos", surname: "Amigos",
mail: "pedrosamigos@hotmail.com", mail: "pedrosamigos@hotmail.com",
password: passwordManager.HashPassword("pamigos")) password: "pamigos")
}) })
#endregion #endregion
} }
}; };
return data; return data;
} }
#region Not supported methods #region Not supported methods
public void Save(Dictionary<string, List<object>> elements) public void Save(Dictionary<string, List<object>> elements)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
public void Export<T>(T obj, string pathToExport) where T : class public void Export<T>(T obj, string pathToExport) where T : class
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
public KeyValuePair<string, T> Import<T>(string pathToImport) where T : class public KeyValuePair<string, T> Import<T>(string pathToImport) where T : class
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
#endregion #endregion
} }
} }

@ -66,8 +66,7 @@ namespace Model
} }
public Review(int stars, string content) public Review(int stars, string content)
: this(new User("admin", "admin", "admin@mctg.fr", new PasswordManager().HashPassword("admin")), : this(new User(), null, stars, content)
null, stars, content)
{ {
} }

@ -17,7 +17,7 @@ namespace Model
/// This user can login with an Id and a password /// This user can login with an Id and a password
/// </summary> /// </summary>
[DataContract(Name = "user")] [DataContract(Name = "user")]
public class User : IEquatable<User> , INotifyPropertyChanged public class User : IEquatable<User> , INotifyPropertyChanged
{ {
#region Private Attributes #region Private Attributes
@ -40,12 +40,9 @@ namespace Model
public string Name public string Name
{ {
get { return name; } get { return name; }
private set set
{ {
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Impossible d'avoir un champ Nom vide!");
}
name = value; name = value;
OnPropertyChanged(); OnPropertyChanged();
} }
@ -58,12 +55,9 @@ namespace Model
public string Surname public string Surname
{ {
get { return surname; } get { return surname; }
private set set
{ {
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Impossible d'avoir un champ Prénom vide!");
}
surname = value; surname = value;
OnPropertyChanged(); OnPropertyChanged();
} }
@ -147,7 +141,7 @@ namespace Model
return $"{Name} {Surname}"; return $"{Name} {Surname}";
} }
public IPasswordManager psswMgr { get; private set; }
#endregion #endregion
@ -161,12 +155,13 @@ namespace Model
/// <param name="name">The name of the user</param> /// <param name="name">The name of the user</param>
/// <param name="surname">The surname of the user</param> /// <param name="surname">The surname of the user</param>
/// <param name="mail">The user needs an email to login. </param> /// <param name="mail">The user needs an email to login. </param>
public User(string name, string surname, string mail, int password) public User(string name, string surname, string mail, string password, IPasswordManager passwordManager )
{ {
Name = name; Name = name;
Surname = surname; Surname = surname;
Mail = mail; Mail = mail;
Password = password; psswMgr = passwordManager;
Password = psswMgr.HashPassword(password);
priorities = new List<Priority> { priorities = new List<Priority> {
Priority.Gourmet, Priority.Gourmet,
Priority.Economic, Priority.Economic,
@ -176,8 +171,30 @@ namespace Model
ProfilPict = picture; 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 #endregion

@ -5,17 +5,20 @@ using Windows.Graphics;
#endif #endif
using DataPersistence; using DataPersistence;
using Model;
namespace Views namespace Views
{ {
public partial class App : Application public partial class App : Application
{ {
public DataManager DataMgr { get; private set; } = new DataManager(new Stubs()); public DataManager DataMgr { get; private set; } = new DataManager(new Stubs());
public User user { get; set; }
const int WindowWidth = 1200; const int WindowWidth = 1200;
const int WindowHeight = 800; const int WindowHeight = 800;
public App() public App()
{ {
user = DataMgr.Data[nameof(User)].Cast<User>().Last();
InitializeComponent(); InitializeComponent();
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>

@ -28,11 +28,19 @@
Style="{StaticResource button2}" Style="{StaticResource button2}"
IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}" IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}"
IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"/> IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"/>
<Label Text="{Binding user}" <StackLayout BindingContext="{Binding user}">
HorizontalOptions="Center" Margin="15" <Label Text="{Binding Name}"
HorizontalOptions="Center" Margin="0,15"
FontSize="20" FontAttributes="Bold" HorizontalTextAlignment="Center" FontSize="20" FontAttributes="Bold" HorizontalTextAlignment="Center"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/> IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/>
<Label Text="{Binding Surname}"
HorizontalOptions="Center"
FontSize="20" FontAttributes="Bold" HorizontalTextAlignment="Center"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"
IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/>
</StackLayout>
</VerticalStackLayout> </VerticalStackLayout>

@ -5,17 +5,17 @@ namespace Views;
public partial class ContainerFlyout : ContentView public partial class ContainerFlyout : ContentView
{ {
public DataManager DataMgr => (App.Current as App).DataMgr; public DataManager DataMgr => (App.Current as App).DataMgr;
public User user { get; private set; } public User user => (App.Current as App).user;
public ContainerFlyout() public ContainerFlyout()
{ {
InitializeComponent();
InitializeComponent(); BindingContext = this;
BindingContext = this;
user = DataMgr.Data[nameof(User)].Cast<User>().Last();
} }
// Bind MyFlyoutContent // Bind MyFlyoutContent
public static readonly BindableProperty MyFlyoutContentProperty = public static readonly BindableProperty MyFlyoutContentProperty =

@ -36,30 +36,27 @@
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20"/> Margin="50,10,0,20"
Text="{Binding userBis.Name}"/>
<Label Text="Prénom :" <Label Text="Prénom :"
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20" Margin="50,10,0,20"
Text="{Binding Surname} "/> Text="{Binding userBis.Surname} "/>
<Label Text="Mail :" <Label Text="Mail :"
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20" Margin="50,10,0,20"
IsEnabled="False" IsEnabled="False"
Text="{Binding Mail}"/> Text="{Binding user.Mail}"/>
<Label Text="Pseudo :"
Padding="50,0,0,0"
FontSize="18"/>
<Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,50"/>
<Button BackgroundColor="#bdf5bd" <Button BackgroundColor="#bdf5bd"
Text="Valider" Text="Valider"
Margin="40,0,0,0" Margin="40,0,0,0"
TextColor="Black" TextColor="Black"
MaximumWidthRequest="100"/> MaximumWidthRequest="100"
Clicked="Validation_Click"/>

@ -1,21 +1,31 @@
using CommunityToolkit.Maui.Behaviors;
using DataPersistence; using DataPersistence;
using Model; using Model;
using System.Diagnostics;
namespace Views; namespace Views;
public partial class MyProfil : ContentPage public partial class MyProfil : ContentPage
{ {
public DataManager DataMgr = (App.Current as App).DataMgr; public DataManager DataMgr => (App.Current as App).DataMgr;
public User user { get; private set; } public User user => (App.Current as App).user;
public User userBis {get; set; }
public MyProfil() public MyProfil()
{ {
DataMgr = new DataManager(new Stubs()); userBis = new User(user);
user = DataMgr.Data[nameof(User)].Cast<User>().Last();
InitializeComponent(); InitializeComponent();
BindingContext = user; BindingContext = this;
}
public void Validation_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(userBis.Name) || String.IsNullOrEmpty(userBis.Surname)){
return;
}
user.Name = userBis.Name;
user.Surname = userBis.Surname;
} }
} }
Loading…
Cancel
Save