Example #1
0
 /// <summary>
 /// The insert note into groups.
 /// </summary>
 /// <param name="note">
 /// The note.
 /// </param>
 /// <param name="groups">
 /// The groups.
 /// </param>
 public void InsertNoteIntoGroups(SimpleNote note, IEnumerable <NoteGroup> groups)
 {
     foreach (var group in groups)
     {
         group.TryAddNote(note);
     }
 }
Example #2
0
        /// <summary>
        /// The try add note.
        /// </summary>
        /// <param name="note">
        /// The note.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool TryAddNote(SimpleNote note)
        {
            if (note.DateModified >= this.startDate && note.DateModified < this.endDate)
            {
                this.Notes.Add(note);
                return(true);
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// The save note async.
        /// </summary>
        /// <param name="note">
        /// The note.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task SaveNoteAsync(SimpleNote note)
        {
            var fileName = note.Id;
            var file     = await this.notesFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

            var data = new[]
            {
                await ProtectDataAsync(note.Title),
                await ProtectDataAsync(note.Description),
                await ProtectDataAsync(note.DateCreated.ToString()),
                await ProtectDataAsync(note.DateModified.ToString())
            };

            await FileIO.WriteLinesAsync(file, data);
        }
Example #4
0
        /// <summary>
        /// The initialize.
        /// </summary>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task InitializeAsync()
        {
            if (this.IsInitialized)
            {
                return;
            }

            await this.dataSource.InitializeAsync();

            var notes = await this.dataSource.LoadNotesAsync();

            if (notes.Count == 0)
            {
                var defaultNote = new SimpleNote
                {
                    Title       = "Tap to Get Started",
                    Description =
                        "This is a simple note to help you get started. Feel free to edit the title and the content."
                };
                this.currentEditableNote = defaultNote;
                this.IsNew = true;
                this.Save();
            }
            else
            {
                foreach (var note in notes)
                {
                    this.groupHelper.InsertNoteIntoGroups(note, this.NoteGroups);
                }

                this.CurrentNote = notes.FirstOrDefault();
                this.GetNotableGroups();
                this.SetTile();
            }

            this.IsInitialized = true;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModel"/> class.
        /// </summary>
        public ViewModel()
        {
            this.NoteGroups    = new ObservableCollection <NoteGroup>();
            this.NotableGroups = new ObservableCollection <NoteGroup>();

            foreach (var group in this.groupHelper.GetGroups())
            {
                this.NoteGroups.Add(group);
            }

            this.GoHome = delegate { };

            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }

            // only design-time logic here
            var random = new Random();

            for (var x = 0; x < 20; x++)
            {
                var note = new SimpleNote
                {
                    Title        = string.Format("Sample Note {0}", x),
                    Description  = new string('*', 999),
                    DateCreated  = DateTime.Now.AddYears(-2),
                    DateModified = DateTime.Now.AddDays(-360 * random.NextDouble())
                };
                this.groupHelper.InsertNoteIntoGroups(note, this.NoteGroups);
            }

            this.GetNotableGroups();

            this.currentNote = this.CurrentEditableNote = this.NotableGroups[0].Notes[0];
        }