convert to use service

This commit is contained in:
2023-01-05 10:32:21 -05:00
parent 596065b7c8
commit 2caa82b8f4
5 changed files with 51 additions and 19 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Mvc;
namespace BinaryDad.Notes.Controllers;
@ -6,11 +7,11 @@ namespace BinaryDad.Notes.Controllers;
[Route("[controller]")]
public class ApiController : ControllerBase
{
private readonly string filePath;
private readonly INoteService noteService;
public ApiController(IConfiguration configuration)
public ApiController(INoteService noteService)
{
filePath = configuration["ContentFilePath"];
this.noteService = noteService;
}
[HttpPost]
@ -24,7 +25,7 @@ public class ApiController : ControllerBase
content = await reader.ReadToEndAsync();
}
await System.IO.File.WriteAllTextAsync(filePath, content);
noteService.Save(content);
return true;
}

View File

@ -1,19 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Mvc;
namespace BinaryDad.Notes.Controllers;
public class HomeController : Controller
{
private readonly string filePath;
private readonly INoteService noteService;
public HomeController(IConfiguration configuration)
public HomeController(INoteService noteService)
{
filePath = configuration["ContentFilePath"];
this.noteService = noteService;
}
public IActionResult Index()
{
var content = System.IO.File.ReadAllText(filePath);
var content = noteService.Get();
return View((object)content);
}