Notes/Controllers/NoteController.cs

36 lines
859 B
C#
Raw Normal View History

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