コード例 #1
0
        public static bool ArchiveNote(Note note, bool reflectOnRoaming = true)
        {
            //get original reference
            if (notes != null)
            {
                note = Notes.FirstOrDefault(x => x.ID == note.ID);
            }
            if (note == null)
            {
                return(false);
            }

            Debug.WriteLine("Archive note: " + note.Title);
            //App.TelemetryClient.TrackEvent("NoteArchived");

            LoadArchivedNotesIfNecessary();
            note.IsArchived = true;
            note.TouchArchivedAt();

            RemoveNoteReminders(note);
            NotificationsManager.RemoveTileIfExists(note.ID);

            bool success = LocalDB.Update(note) == 1;

            if (!success)
            {
                return(false);
            }

            if (reflectOnRoaming)
            {
                RoamingDB.Update(note);
            }

            AppData.Notes.Remove(note);
            AppData.ArchivedNotes.Insert(0, note);
            Debug.WriteLine("AppData.ArchivedNotes.Insert(0, note);");

            var handler = NoteArchived;

            if (handler != null)
            {
                handler(null, new NoteEventArgs(note));
            }

            var handler2 = NotesSaved;

            if (handler2 != null)
            {
                handler2(null, EventArgs.Empty);
            }

            return(true);
        }
コード例 #2
0
        public static async Task <bool> RemoveNote(Note note, bool reflectOnRoaming = true)
        {
            if (note == null)
            {
                return(false);
            }

            Note noteFound = null;

            //get original reference
            if (notes != null)
            {
                try
                {
                    if (note.IsArchived)
                    {
                        LoadArchivedNotesIfNecessary();
                        noteFound = ArchivedNotes.FirstOrDefault(x => x.ID == note.ID);
                        if (ArchivedNotes.IndexOf(noteFound) < 0)
                        {
                            noteFound = null;
                        }
                    }
                    else
                    {
                        noteFound = Notes.FirstOrDefault(x => x.ID == note.ID);
                        if (Notes.IndexOf(note) < 0)
                        {
                            noteFound = null;
                        }
                    }
                }
                catch (Exception)
                {
                    Debug.WriteLine("Failed removing note.");
                    return(false);
                }
            }

            Debug.WriteLine("Remove note: " + note.Title);
            //App.TelemetryClient.TrackEvent("NoteRemoved");

            //remove note images from disk
            await RemoveNoteImages(note.Images);

            RemoveNoteReminders(note);
            NotificationsManager.RemoveTileIfExists(note.ID);

            if (noteFound == null)
            {
                return(false);
            }

            noteFound.SoftDelete();

            bool success = LocalDB.Update(noteFound) == 1;

            if (!success)
            {
                return(false);
            }

            if (reflectOnRoaming)
            {
                RoamingDB.Update(noteFound);
            }

            //LocalDB.Delete(noteFound);
            //RoamingDB.Delete(noteFound);

            AppData.Notes.Remove(noteFound);
            AppData.ArchivedNotes.Remove(noteFound);

            var handler = NoteRemoved;

            if (handler != null)
            {
                handler(null, new NoteIdEventArgs(noteFound.ID));
            }

            var handler2 = NotesSaved;

            if (handler2 != null)
            {
                handler2(null, EventArgs.Empty);
            }

            return(true);
        }