Notes/Services/FileNoteService.cs

23 lines
643 B
C#
Raw Normal View History

2023-01-05 15:32:21 +00:00
namespace BinaryDad.Notes.Services
{
public class FileNoteService : INoteService
{
private readonly string? filePath;
public FileNoteService(IConfiguration configuration)
{
filePath = configuration["ContentFilePath"];
// ensure initialized
if (!File.Exists(filePath))
{
2023-02-07 16:52:44 +00:00
Save("Hi! Feel free to start typing. Everything will be saved soon after you are done typing.");
2023-01-05 15:32:21 +00:00
}
}
2023-07-28 18:52:53 +00:00
public string Get() => File.ReadAllText(filePath);
2023-01-05 15:32:21 +00:00
2023-07-28 18:52:53 +00:00
public void Save(string content) => File.WriteAllText(filePath, content);
2023-01-05 15:32:21 +00:00
}
}