29 lines
731 B
C#
29 lines
731 B
C#
|
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))
|
|||
|
{
|
|||
|
File.WriteAllText(filePath, "Hi! Feel free to start typing. Everything will be saved soon after you are done typing.");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string Get()
|
|||
|
{
|
|||
|
return File.ReadAllText(filePath);
|
|||
|
}
|
|||
|
|
|||
|
public void Save(string content)
|
|||
|
{
|
|||
|
File.WriteAllText(filePath, content);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|