Notes/Controllers/NoteController.cs
2023-05-17 21:44:41 -04:00

39 lines
873 B
C#

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