first commit i guess

This commit is contained in:
Krzysztof KrzysiekSiemv Smaga
2025-03-26 01:01:06 +01:00
commit 321b6a07df
1973 changed files with 119622 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
using System.Collections.ObjectModel;
using System.Text.Json;
using NoteApp.Model;
namespace NoteApp.Service;
public class FileService {
private readonly string _fileName;
public FileService(){
_fileName = Path.Combine(FileSystem.AppDataDirectory, "notes.json");
}
public async Task<ObservableCollection<Note>> LoadNotes(){
if(!File.Exists(_fileName))
return [];
var json = await File.ReadAllTextAsync(_fileName);
return JsonSerializer.Deserialize<ObservableCollection<Note>>(json) ?? [];
}
public async Task SaveNotes(ObservableCollection<Note> notes){
var json = JsonSerializer.Serialize(notes);
await File.WriteAllTextAsync(_fileName, json);
}
}