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

@ -14,7 +14,6 @@ namespace DataPersistence
{ {
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>>
{ {
@ -98,12 +97,13 @@ namespace DataPersistence
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
} }

@ -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)
{ {
} }

@ -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,7 +171,29 @@ 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>

@ -6,15 +6,15 @@ 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

@ -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