Notes/Controllers/NoteController.cs

36 lines
859 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
2023-07-28 18:52:53 +00:00
public NoteController(INoteService noteService) => this.noteService = noteService;
2022-11-29 15:14:15 +00:00
2024-01-07 02:00:49 +00:00
[Route("{noteName=default}")]
2023-05-18 01:44:41 +00:00
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,
2024-05-08 01:43:09 +00:00
Text = noteService.GetNote(noteName),
2023-05-12 16:38:13 +00:00
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
}
}