Notes/Controllers/NoteController.cs

39 lines
873 B
C#
Raw Normal View History

using BinaryDad.Notes.Models;
2023-05-12 16:38:13 +00:00
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Authorization;
2023-01-05 15:32:21 +00:00
using Microsoft.AspNetCore.Mvc;
2022-11-29 15:14:15 +00:00
namespace BinaryDad.Notes.Controllers;
[Authorize]
public class NoteController : Controller
2022-11-29 15:14:15 +00:00
{
2023-01-05 15:32:21 +00:00
private readonly INoteService noteService;
2022-11-29 15:14:15 +00:00
public NoteController(INoteService noteService)
2022-11-29 15:14:15 +00:00
{
2023-01-05 15:32:21 +00:00
this.noteService = noteService;
2022-11-29 15:14:15 +00:00
}
2023-05-18 01:44:41 +00:00
[Route("{noteName=default}")]
public IActionResult Index(string noteName)
2022-11-29 15:14:15 +00:00
{
2023-05-12 16:38:13 +00:00
var model = new ContentModel
{
2023-05-18 01:44:41 +00:00
CurrentNote = noteName,
2023-05-12 16:38:13 +00:00
Text = noteService.GetText(noteName),
NoteNames = noteService.GetNoteNames()
};
2022-11-29 15:14:15 +00:00
2023-05-12 16:38:13 +00:00
return View(model);
2022-11-29 15:14:15 +00:00
}
2023-05-12 16:47:54 +00:00
[Route("{noteName}/delete")]
public IActionResult Delete(string noteName)
{
noteService.DeleteNote(noteName);
return Redirect("/");
}
2022-11-29 15:14:15 +00:00
}