예제 #1
0
        private static bool CreateNote(Note note, bool reflectOnRoaming = true)
        {
            if (note == null || note.IsEmpty())
            {
                return(false);
            }

            Debug.WriteLine("Create note: " + note.Title);
            //App.TelemetryClient.TrackEvent("NoteCreated");

            //associate with note
            foreach (var item in note.Checklist)
            {
                item.NoteId = note.ID;
            }
            foreach (var item in note.Images)
            {
                item.NoteId = note.ID;
            }
            note.Reminder.NoteId = note.ID;

            if (note.CreatedAt == null)
            {
                note.TouchCreatedAt();
            }
            if (note.UpdatedAt == null)
            {
                note.Touch();
            }

            note.Changed = false;
            note.Order   = Notes.Count;
            AppData.Notes.Insert(0, note);

            NotificationsManager.TryCreateNoteReminder(note, note.Reminder.Date);

            LocalDB.InsertWithChildren(note);
            if (reflectOnRoaming)
            {
                RoamingDB.InsertWithChildren(note);
            }

            var handler = NoteCreated;

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

            var handler2 = NotesSaved;

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

            return(true);
        }
예제 #2
0
        public static bool RestoreNote(Note note, bool reflectOnRoaming = true)
        {
            LoadArchivedNotesIfNecessary();

            //get original reference
            if (notes != null)
            {
                note = ArchivedNotes.FirstOrDefault(x => x.ID == note.ID);
            }
            if (note == null)
            {
                return(false);
            }

            Debug.WriteLine("Restore note: " + note.Title);
            //App.TelemetryClient.TrackEvent("ArchivedNoteRestored");

            note.IsArchived = false;
            note.Order      = Notes.Count;

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

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

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

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

            NotificationsManager.TryCreateNoteReminder(note, note.Reminder.Date);

            var handler = NoteRestored;

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

            var handler2 = NotesSaved;

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

            return(true);
        }