public void Update() { if (Contact.Count() != 0) { Serialisation.Serialiser(Contact, chemin); Contact = (List <Model.Contact>)Serialisation.Deserialiser(chemin); } else { File.Delete(chemin); } }
public void ReceiveMessage(NotificationMessage notificationMessage) { string notification = notificationMessage.Notification; if (notification == "ajouterContact") { if (File.Exists(chemin) == true) { Contact = (List <Model.Contact>)Serialisation.Deserialiser(chemin); } } //do your work }
public MainViewModel(INavigationService navigationService) { this.navigationService = navigationService; MessengerInstance.Register <NotificationMessage>(this, ReceiveMessage); Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; string folderPath = localFolder.Path; chemin = Path.Combine(folderPath, @"Contact.bin"); if (File.Exists(chemin) == true) { Contact = (List <Model.Contact>)Serialisation.Deserialiser(chemin); } }
public async void ValiderContact() { var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var folderPath = localFolder.Path; var chemin = Path.Combine(folderPath, @"Contact.bin"); int test = 0; bool isNumberTel = int.TryParse(tbNum, out test); bool isContainsMail = tbMail.Contains("@"); if (isNumberTel == true && isContainsMail == true) { if (File.Exists(chemin) == true) { contact = (List <Contact>)Serialisation.Deserialiser(chemin); contact.Add(new Contact() { Nom = tbNom, Prenom = tbPrenom, Numtel = tbNum, Mail = tbMail }); Serialisation.Serialiser(contact, chemin); } else { contact.Add(new Contact() { Nom = tbNom, Prenom = tbPrenom, Numtel = tbNum, Mail = tbMail }); Serialisation.Serialiser(contact, chemin); } MessengerInstance.Send <NotificationMessage>(new NotificationMessage("ajouterContact")); Prenom = ""; Nom = ""; Num = ""; Mail = ""; navigationService.GoBack(); } else { if (isNumberTel == false) { var dialog = new MessageDialog("Le numéro de téléphone est incorrect!"); await dialog.ShowAsync(); } else { var dialog = new MessageDialog("Le mail est incorrect!"); await dialog.ShowAsync(); } } }