Ejemplo n.º 1
0
        public static void RemoveNoteReminders(Note note, bool reflectOnRoaming = true)
        {
            if (note == null || note.Reminder == null)
            {
                return;
            }

            LocalDB.Delete(note.Reminder);
            if (reflectOnRoaming)
            {
                RoamingDB.Delete(note.Reminder);
            }

            NotificationsManager.RemoveScheduledToastsIfExists(note);
            note.Reminder = new Reminder();
        }
Ejemplo n.º 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);
        }