2023-08-04 18:26:22 -04:00
|
|
|
|
using BinaryDad.Notes.Models;
|
2023-05-12 12:38:13 -04:00
|
|
|
|
using BinaryDad.Notes.Services;
|
2023-05-10 16:22:51 -04:00
|
|
|
|
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;
|
|
|
|
|
|
2023-05-10 16:22:51 -04:00
|
|
|
|
[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,
|
2024-05-07 21:43:09 -04:00
|
|
|
|
Text = noteService.GetNote(noteName),
|
2023-05-12 12:38:13 -04:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|