1
using CommunityToolkit.Mvvm.ComponentModel;
2
using CommunityToolkit.Mvvm.Input;
6
using System.Collections.Generic;
7
using System.Collections.ObjectModel;
9
using System.Net.WebSockets;
11
using System.Threading.Tasks;
12
using ViewModel.Services;
16
public partial class MainViewModel: ObservableObject
18
private NoteViewModel _selectedNote;
20
private string? _searchNoteTitle;
23
private bool _isEnabled = false;
26
private void AddNote()
28
var note = new NoteViewModel();
31
if (SelectedNote != null)
33
SelectedNote.IsEdit = true;
35
if (Notes.Contains(note))
37
NotesSerializer.Serialize(Transfers.TransferNoteVMToNoteDTO(Notes));
38
if (SelectedNote != null)
40
SelectedNote.IsEdit = false;
46
NotesSerializer.Serialize(Transfers.TransferNoteVMToNoteDTO(Notes));
47
if (SelectedNote != null)
49
SelectedNote.IsEdit = false;
52
SelectedNote = Notes.Last();
57
private void DeleteNote()
61
if (SelectedNote == Notes.Last())
63
Notes.Remove(SelectedNote);
66
SelectedNote = Notes.Last();
77
foreach (var note in Notes)
79
if (SelectedNote == note)
81
Notes.Remove(SelectedNote);
89
NotesSerializer.Serialize(Transfers.TransferNoteVMToNoteDTO(Notes));
90
if (SelectedNote != null)
92
SelectedNote.IsEdit = false;
97
private void SaveNote()
99
NotesSerializer.Serialize(Transfers.TransferNoteVMToNoteDTO(Notes));
100
SelectedNote.IsEdit = false;
103
public ObservableCollection<NoteViewModel> Notes { get; set; } =
104
NotesSerializer.Deserialize();
106
public NoteViewModel? SelectedNote
108
get => _selectedNote;
113
var keepId = value.Id;
114
if (_selectedNote != null)
116
if (_selectedNote.Id != keepId)
118
_selectedNote.IsEdit = false;
122
_selectedNote = value;
125
NotesSerializer.Serialize(Transfers.TransferNoteVMToNoteDTO(Notes));
129
public string SearchNoteTitle
131
get => _searchNoteTitle;
134
_searchNoteTitle = value;
135
if (_searchNoteTitle != null)
138
foreach(var note in Notes)
140
if (_searchNoteTitle == note.Title)
146
else if (note.Title.StartsWith(_searchNoteTitle))