public static async Task <bool> CreateOrUpdateNote(Note note, bool reflectOnRoaming = true) { if (note == null) { return(false); } bool alreadyExists = LocalDB.Find <Note>(note.ID) != null; if (note.IsEmpty()) { return(await RemoveNote(note, reflectOnRoaming)); } else { return(alreadyExists ? UpdateNote(note, reflectOnRoaming) : CreateNote(note, reflectOnRoaming)); } }
private static async void MergeRoamingWithLocalDB() { var allLocalNotes = LocalDB.GetAllWithChildren <Note>(); var allRoamingNotes = RoamingDB.GetAllWithChildren <Note>(); foreach (var roamingNote in allRoamingNotes) { var localNote = LocalDB.Find <Note>(roamingNote.ID); //create local note if (localNote == null) { CreateNote(roamingNote, false); Debug.WriteLine("Roaming: Note created"); } //archive local note else if (roamingNote.IsArchived && !localNote.IsArchived && roamingNote.ArchivedAt > localNote.UpdatedAt) { ArchiveNote(localNote, false); UpdateNote(roamingNote, false); localNote.ReplaceWith(roamingNote); Debug.WriteLine("Roaming: Note archived"); } //delete local note else if (roamingNote.DeletedAt != localNote.DeletedAt && roamingNote.DeletedAt > localNote.UpdatedAt) { await RemoveNote(localNote, false); UpdateNote(roamingNote, false); localNote.ReplaceWith(roamingNote); Debug.WriteLine("Roaming: Note deleted"); } //update local note else if (roamingNote.UpdatedAt > localNote.UpdatedAt) { UpdateNote(roamingNote, false); localNote.ReplaceWith(roamingNote); Debug.WriteLine("Roaming: Note updated"); } } }