diff --git a/Sources/Model/Animal.cs b/Sources/Model/Animal.cs
index e80817e..246b500 100644
--- a/Sources/Model/Animal.cs
+++ b/Sources/Model/Animal.cs
@@ -44,7 +44,7 @@ namespace Model
private bool nomIsValid;
[DataMember(Name = "naissance")]
- public string DateNaissance
+ public DateTime DateNaissance
{
get => dateNaissance;
set
@@ -55,7 +55,7 @@ namespace Model
OnPropertyChanged(nameof(DateNaissance));
}
}
- private string dateNaissance;
+ private DateTime dateNaissance;
[DataMember(Name = "sexe")]
public string Sexe
@@ -71,7 +71,7 @@ namespace Model
private string sexe;
[DataMember(Name = "adoption")]
- public string DateAdoption
+ public DateTime DateAdoption
{
get => dateAdoption;
set
@@ -82,7 +82,7 @@ namespace Model
OnPropertyChanged(nameof(DateAdoption));
}
}
- private string dateAdoption;
+ private DateTime dateAdoption;
[DataMember(Name = "taille")]
public float? Taille
@@ -238,12 +238,10 @@ namespace Model
}
private string image;
- public Animal(string nom = "", string dateNaissance = "Inconnue", string sexe = "Inconnu", string dateAdpotion = "Inconnue", float? taille = null, float? poids = null, string alimentation = "Inconnue")
+ public Animal(string nom = "", string sexe = "Inconnu", float? taille = null, float? poids = null, string alimentation = "Inconnue")
{
Nom = nom;
- DateNaissance = dateNaissance;
Sexe = sexe;
- DateAdoption = dateAdpotion;
Taille = taille;
Poids = poids;
Alimentation = alimentation;
diff --git a/Sources/Persistance/DataSerializer.cs b/Sources/Persistance/DataSerializer.cs
index cd3216f..3e7195c 100644
--- a/Sources/Persistance/DataSerializer.cs
+++ b/Sources/Persistance/DataSerializer.cs
@@ -12,11 +12,11 @@ namespace Persistance
{
public class DataSerializer
{
- public void Serializer()
+ public static void Serializer(String path)
{
Theque theque = new Theque();
- Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory()));
+ Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
string xmlFile = "theque.xml";
var serializer = new DataContractSerializer(typeof(Theque));
@@ -27,20 +27,25 @@ namespace Persistance
}
}
- public Theque Deserializer()
+ public static Theque Deserializer(String path)
{
- string path = FileSystem.
- Directory.SetCurrentDirectory();
+ Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory()));
string xmlFile = "theque.xml";
var serializer = new DataContractSerializer(typeof(Theque));
Theque theque = new Theque();
- using (Stream s = File.OpenRead(xmlFile))
+ if(File.Exists(xmlFile))
+ {
+ using (Stream s = File.OpenRead(xmlFile))
+ {
+ theque = serializer.ReadObject(s) as Theque;
+ }
+ }
+ else
{
- theque = serializer.ReadObject(s) as Theque;
+ theque = Stub.LoadTheque();
}
-
return theque;
}
}
diff --git a/Sources/Views/App.xaml.cs b/Sources/Views/App.xaml.cs
index abc4431..ad2c0f1 100644
--- a/Sources/Views/App.xaml.cs
+++ b/Sources/Views/App.xaml.cs
@@ -1,4 +1,5 @@
using Model;
+using Persistance;
using System.ComponentModel;
using System.Runtime.CompilerServices;
@@ -6,8 +7,9 @@ namespace Views
{
public partial class App : Application, INotifyPropertyChanged
{
- string path = FileSystem.Current.AppDataDirectory;
- public Theque Theque { get; set; } = Stub.LoadTheque();
+ public string SerializationPath = FileSystem.Current.AppDataDirectory;
+ static private string serializationPath = FileSystem.Current.AppDataDirectory;
+ public Theque Theque { get; set; } = DataSerializer.Deserializer(serializationPath);
public Animal AnimalSelectionner
{
get => animalSelectionner;
@@ -17,8 +19,9 @@ namespace Views
OnPropertyChanged(nameof(AnimalSelectionner));
}
}
- public New_DetailAnimal PageDeSaisie { get; set; }
private Animal animalSelectionner;
+
+ public New_DetailAnimal PageDeSaisie { get; set; }
public Espece EspeceSelectionner { get; set; }
public Race RaceSelectionner { get; set; }
diff --git a/Sources/Views/New_DetailAnimal.xaml b/Sources/Views/New_DetailAnimal.xaml
index b15af7b..5f803db 100644
--- a/Sources/Views/New_DetailAnimal.xaml
+++ b/Sources/Views/New_DetailAnimal.xaml
@@ -54,9 +54,10 @@
RowSpacing="8">
-
+
@@ -67,10 +68,11 @@
-
+
diff --git a/Sources/Views/New_DetailAnimal.xaml.cs b/Sources/Views/New_DetailAnimal.xaml.cs
index 122056c..7e2f62c 100644
--- a/Sources/Views/New_DetailAnimal.xaml.cs
+++ b/Sources/Views/New_DetailAnimal.xaml.cs
@@ -1,67 +1,69 @@
-using Model;
+using Model;
+using Persistance;
using System.Dynamic;
-namespace Views;
-
-public partial class New_DetailAnimal : ContentPage
-{
- private Animal AnimalSelectione => (App.Current as App).AnimalSelectionner;
-
- public New_DetailAnimal()
- {
- InitializeComponent();
- (App.Current as App).PageDeSaisie = this;
- InitBinding();
- }
-
+namespace Views;
+
+public partial class New_DetailAnimal : ContentPage
+{
+ private Animal AnimalSelectione => (App.Current as App).AnimalSelectionner;
+
+ public New_DetailAnimal()
+ {
+ InitializeComponent();
+ (App.Current as App).PageDeSaisie = this;
+ InitBinding();
+ }
+
public void InitBinding()
{
- BindingContext = AnimalSelectione;
+ BindingContext = AnimalSelectione;
Picker_especes.BindingContext = (App.Current as App).Theque;
- }
-
- public async void Button_OnClick(object sender, EventArgs e)
- {
- (App.Current as App).Theque.SupprimerAnimal((App.Current as App).AnimalSelectionner);
- await Shell.Current.GoToAsync("//Animaux");
- }
-
- public async void Validate_OnClick(object sender, EventArgs e)
- {
+ }
+
+ public async void Button_OnClick(object sender, EventArgs e)
+ {
+ (App.Current as App).Theque.SupprimerAnimal((App.Current as App).AnimalSelectionner);
+ await Shell.Current.GoToAsync("//Animaux");
+ }
+
+ public async void Validate_OnClick(object sender, EventArgs e)
+ {
if ((App.Current as App).AnimalSelectionner.NomIsValid == true)
{
await Shell.Current.GoToAsync("//Animaux");
- }
- }
-
- private void EspeceClic(object sender, EventArgs e)
- {
- (App.Current as App).AnimalSelectionner.Espece = (sender as Picker).SelectedItem as Espece;
- (App.Current as App).AnimalSelectionner.Race = null;
- }
-
- private void RaceClic(object sender, EventArgs e)
- {
- (App.Current as App).AnimalSelectionner.Race = (sender as Picker).SelectedItem as Race;
- }
-
- public async void TakePhoto(object sender, EventArgs e)
- {
- if (MediaPicker.Default.IsCaptureSupported)
- {
- FileResult photo = await MediaPicker.Default.PickPhotoAsync();
-
- if (photo != null)
- {
- string localFilePath = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
-
- using Stream sourceStream = await photo.OpenReadAsync();
- using FileStream localFileStream = File.OpenWrite(localFilePath);
-
- await sourceStream.CopyToAsync(localFileStream);
-
- (App.Current as App).AnimalSelectionner.Image = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
- }
- }
- }
+ DataSerializer.Serializer((App.Current as App).SerializationPath);
+ }
+ }
+
+ private void EspeceClic(object sender, EventArgs e)
+ {
+ (App.Current as App).AnimalSelectionner.Espece = (sender as Picker).SelectedItem as Espece;
+ (App.Current as App).AnimalSelectionner.Race = null;
+ }
+
+ private void RaceClic(object sender, EventArgs e)
+ {
+ (App.Current as App).AnimalSelectionner.Race = (sender as Picker).SelectedItem as Race;
+ }
+
+ public async void TakePhoto(object sender, EventArgs e)
+ {
+ if (MediaPicker.Default.IsCaptureSupported)
+ {
+ FileResult photo = await MediaPicker.Default.PickPhotoAsync();
+
+ if (photo != null)
+ {
+ string localFilePath = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
+
+ using Stream sourceStream = await photo.OpenReadAsync();
+ using FileStream localFileStream = File.OpenWrite(localFilePath);
+
+ await sourceStream.CopyToAsync(localFileStream);
+
+ (App.Current as App).AnimalSelectionner.Image = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Sources/Views/Views.csproj b/Sources/Views/Views.csproj
index 605d914..f033b9d 100644
--- a/Sources/Views/Views.csproj
+++ b/Sources/Views/Views.csproj
@@ -55,6 +55,7 @@
+