first commit i guess
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user