44 lines
1.0 KiB
C#
44 lines
1.0 KiB
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.GetNote(noteName),
|
|
NoteNames = noteService.GetNoteNames()
|
|
};
|
|
|
|
return View(model);
|
|
}
|
|
|
|
[HttpPost, Route("create")]
|
|
public IActionResult Create(string noteName)
|
|
{
|
|
noteService.SaveNote(noteName);
|
|
|
|
return Redirect($"/{noteName}");
|
|
}
|
|
|
|
[Route("delete/{noteName}")]
|
|
public IActionResult Delete(string noteName)
|
|
{
|
|
noteService.DeleteNote(noteName);
|
|
|
|
return Redirect("/");
|
|
}
|
|
}
|