/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel(INoteRepository noteRepository, ICategoryRepository categoryRepository) { _noteRepository = noteRepository; _categoryRepository = categoryRepository; Notes = new ObservableCollection<Note>(_noteRepository.FindAll()); Categories = new ObservableCollection<Category>(_categoryRepository.FindAll()); // Is there categories list empty? if (Categories.Count == 0) { // In this case, I will create a default category with a welcome note var cat = new Category(Resources.Strings.GeneralCat, "#33CC00", "#FFFFFF"); Categories.Add(cat); _categoryRepository.SaveAll(Categories); var note = new Note(Resources.Strings.WelcomeMessage, cat); Notes.Add(note); _noteRepository.Save(note); } ActualNote = new Note(); SelectedCategory = _categories[0]; // We need to this for Category's ComboBox sake. Trash = new Category("Trash", "#f8f8f8", "#777777"); AddNoteCommand = new RelayCommand(AddNote, CanAddNote); EditNoteCommand = new RelayCommand<Note>(EditNote); DeleteNoteCommand = new RelayCommand<Note>(DeleteNote); DeleteAllNotesCommand = new RelayCommand(DeleteAllNotes); CategoryOptionsCommand = new RelayCommand(OpenCategoryOptions); // We expect a message with some lists with changes. Messenger.Default.Register<CategoryEditorChangesMessage>(this, MakingNewCatChanges); }
public void YouCantAddTheSameNoteTwice() { var noteMock = new Mock<INoteRepository>(); var categoryMock = new Mock<ICategoryRepository>(); categoryMock.Setup(rep => rep.FindAll()).Returns(new List<Category> { new Category("Dummy", "#123123123", "#123123123") }); noteMock.Setup(rep => rep.FindAll()).Returns(new List<Note>()); var viewModel = new MainViewModel(noteMock.Object, categoryMock.Object); var note = new Note("A note", viewModel.Categories.First()); viewModel.ActualNote = note; viewModel.AddNoteCommand.Execute(null); var count = viewModel.Notes.Count; viewModel.ActualNote = note; viewModel.AddNoteCommand.Execute(null); Assert.AreEqual(count, viewModel.Notes.Count); }
/// <summary> /// Edits the selected note. /// </summary> /// <param name="other">The selected note.</param> private void EditNote(Note other) { ActualNote = other; SelectedCategory = other.Category; }
/// <summary> /// Deletes the selected note. /// </summary> /// <param name="other">The selected note.</param> private void DeleteNote(Note other) { if (other == null) return; Notes.Remove(other); _noteRepository.Delete(other); }
/// <summary> /// Adds a note to the list and repo. /// </summary> private void AddNote() { if (ActualNote.Content == string.Empty) return; // We don't want an empty note :) ActualNote.Category = SelectedCategory; if (!Notes.Contains(ActualNote)) Notes.Add(ActualNote); _noteRepository.Save(ActualNote); ActualNote = new Note(); if (SelectedCategory.Name == "Trash") // We don't want the Trash selectionable SelectedCategory = Categories[0]; }
/// <summary> /// Changes the note category. /// </summary> /// <param name="theNote">The note.</param> /// <param name="newCategory">The new category.</param> public void ChangeNoteCategory(Note theNote, Category newCategory) { // Selecting the right note var note = Notes.Single(n => n == theNote); note.Category = newCategory; _noteRepository.Save(note); }