diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 8841348..02fc0c4 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -24,4 +24,12 @@ public class HomeController : Controller return View(model); } + + [Route("{noteName}/delete")] + public IActionResult Delete(string noteName) + { + noteService.DeleteNote(noteName); + + return Redirect("/"); + } } diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index 6d1eed5..93c7297 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -32,6 +32,13 @@ File.WriteAllText(GetFilePath(noteName), content); } + public void DeleteNote(string noteName) + { + var filePath = GetFilePath(noteName); + + File.Delete(filePath); + } + private void CheckFile(string noteName) { var filePath = GetFilePath(noteName); diff --git a/Services/INoteService.cs b/Services/INoteService.cs index a5467b2..7d9ff99 100644 --- a/Services/INoteService.cs +++ b/Services/INoteService.cs @@ -5,5 +5,6 @@ ICollection GetNoteNames(); string GetText(string? noteName); void SaveText(string content, string? noteName); + void DeleteNote(string noteName); } }