private async Task saveChangesAsync() { if (nameEntry.Text == null || nameEntry.Text == "") { await parentPage.DisplayAlert("Warning", "Contact must have name", "Ok"); return; } string filePath; if (this.contactMedia == null) { filePath = Path.Combine(FilePaths.allContactsPath, $@"{Guid.NewGuid()}" + ".contact"); IFile file = await FileSystem.Current.LocalStorage.CreateFileAsync(filePath, CreationCollisionOption.FailIfExists); } else { filePath = contactMedia.filePath; } ContactMediaContent newContactMedia = contactMedia; // update fields on contact media if (newContactMedia == null) { newContactMedia = new ContactMediaContent(filePath); } newContactMedia.initialize(nameEntry.Text, phoneEntry.Text, imageFilePath); // If null add to card if (this.contactMedia == null) { parentCard?.addMedia(newContactMedia); MediaManager.addNewMedia(newContactMedia); } this.capturedMedia = newContactMedia; this.contactMedia = this.capturedMedia as ContactMediaContent; JSONSerialManager.serialize(filePath, newContactMedia); //await Navigation.PopAsync(); }
public void saveToFile() { JSONSerialManager.serialize(Path.Combine(FilePaths.allCardsPath, this.name), this); }