Notes/Controllers/HomeController.cs
2023-05-12 12:47:54 -04:00

36 lines
780 B
C#

using BinaryDad.Notes.Models;
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Mvc;
namespace BinaryDad.Notes.Controllers;
public class HomeController : Controller
{
private readonly INoteService noteService;
public HomeController(INoteService noteService)
{
this.noteService = noteService;
}
[Route("{noteName?}")]
public IActionResult Index(string? noteName)
{
var model = new ContentModel
{
Text = noteService.GetText(noteName),
NoteNames = noteService.GetNoteNames()
};
return View(model);
}
[Route("{noteName}/delete")]
public IActionResult Delete(string noteName)
{
noteService.DeleteNote(noteName);
return Redirect("/");
}
}