Notes/Controllers/ApiController.cs
2022-11-29 10:14:15 -05:00

32 lines
666 B
C#

using Microsoft.AspNetCore.Mvc;
namespace BinaryDad.Notes.Controllers;
[ApiController]
[Route("[controller]")]
public class ApiController : ControllerBase
{
private readonly string filePath;
public ApiController(IConfiguration configuration)
{
filePath = configuration["ContentFilePath"];
}
[HttpPost]
[Route("save")]
public async Task<bool> Save()
{
var content = string.Empty;
using (var reader = new StreamReader(Request.Body))
{
content = await reader.ReadToEndAsync();
}
await System.IO.File.WriteAllTextAsync(filePath, content);
return true;
}
}