diff --git a/MCTG/Model/Users/User.cs b/MCTG/Model/Users/User.cs index ba77510..c1ec729 100644 --- a/MCTG/Model/Users/User.cs +++ b/MCTG/Model/Users/User.cs @@ -17,6 +17,7 @@ namespace Model [DataMember(Name = "name")] private string _name = ""; [DataMember(Name = "surname")] private string _surname = ""; [DataMember(Name = "mail")] private string _mail = ""; + [DataMember(Name = "profilepic")] private string _profilePict = "default_picture.png"; [DataMember(Name = "priorities")] private readonly List _priorities = new List @@ -93,8 +94,15 @@ namespace Model /// For now, we define the ProfilePict as a string which is "PhotoParDefaut" /// when the value is null. /// - [DataMember(Name = "profilepic")] - public string ProfilePict { get; private set; } = "default_picture.png"; + public string ProfilePict + { + get => _profilePict; + set + { + _profilePict = value; + OnPropertyChanged(); + } + } /// /// This is the list of priorities specific tu the user. This list is initiate diff --git a/MCTG/Views/ContentViews/ContainerFlyout.xaml b/MCTG/Views/ContentViews/ContainerFlyout.xaml index 300304b..8917a1d 100644 --- a/MCTG/Views/ContentViews/ContainerFlyout.xaml +++ b/MCTG/Views/ContentViews/ContainerFlyout.xaml @@ -15,14 +15,21 @@ - + Clicked="ProfileButton_Clicked"> + + + + + + diff --git a/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs b/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs index 3cdc8ca..7ddb29b 100644 --- a/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs +++ b/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs @@ -1,5 +1,6 @@ using DataPersistence; using Model; +using System.Diagnostics; namespace Views; @@ -50,4 +51,29 @@ public partial class ContainerFlyout : ContentView Master.User.LogOut(); Navigation.PopModalAsync(); } + + public async void ChangeProfilePict_Clicked(object sender, EventArgs e) + { + FileResult photo = await MediaPicker.Default.PickPhotoAsync(); + + if (photo != null) + { + // save the file into local storage + string localFilePath = Path.Combine(FileSystem.Current.AppDataDirectory, $"{Master.User.CurrentConnected.Mail}.{photo.FileName}"); + + using Stream sourceStream = await photo.OpenReadAsync(); + using FileStream localFileStream = File.OpenWrite(localFilePath); + + await sourceStream.CopyToAsync(localFileStream); + + Master.User.CurrentConnected.ProfilePict = localFilePath; + + // Save data. + Debug.Write($"[ {DateTime.Now:H:mm:ss} ] Saving...\t"); + Master.Data.SaveData(); + + Debug.WriteLine("Done."); + Debug.WriteLine(FileSystem.Current.AppDataDirectory); + } + } }