77 lines
1.8 KiB
C#
77 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Notes.Models;
|
|
|
|
namespace Notes.ViewModels;
|
|
|
|
|
|
public partial class AllNotesViewModel: ViewModelBase
|
|
{
|
|
private readonly IServices _services;
|
|
|
|
[ObservableProperty]
|
|
private ObservableCollection<Note> _notes;
|
|
|
|
[ObservableProperty]
|
|
private ObservableCollection<Note> _selected;
|
|
|
|
private Models.Notes _originNotes;
|
|
|
|
|
|
[RelayCommand]
|
|
public void NewNote()
|
|
{
|
|
this._services.GetSafeAs<MainViewModel>().Navitation<NoteViewModel>();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void DeleteNote()
|
|
{
|
|
|
|
}
|
|
|
|
public void DeleteNote(IEnumerable<NoteViewModel> selection)
|
|
{
|
|
foreach (var noteViewModel in selection)
|
|
{
|
|
var note = noteViewModel.Note;
|
|
Notes.Remove(note);
|
|
_originNotes.Delete(note);
|
|
}
|
|
}
|
|
[RelayCommand]
|
|
public void OpenAbout()
|
|
{
|
|
this._services.GetSafeAs<MainViewModel>().Navitation<AboutViewModel>();
|
|
}
|
|
[RelayCommand]
|
|
public void OpenNote(Note note)
|
|
{
|
|
this._services.GetSafeAs<MainViewModel>().OpenNote(note);
|
|
}
|
|
|
|
public AllNotesViewModel(IServices services)
|
|
{
|
|
this._services = services;
|
|
this._originNotes = new Models.Notes();
|
|
_notes = new ObservableCollection<Note>(this._originNotes.notes);
|
|
}
|
|
|
|
|
|
public void AddNote(NoteViewModel viewModel)
|
|
{
|
|
var viewModelNote = viewModel.Note;
|
|
if (Notes.Contains(viewModelNote))
|
|
{
|
|
return;
|
|
}
|
|
if (this.Notes.Any(x=>x.Filename == viewModel.Note.Filename))
|
|
{
|
|
return;
|
|
}
|
|
Notes.Add(viewModelNote);
|
|
this._originNotes.notes.Add(viewModelNote);
|
|
}
|
|
} |