add delete endpoint

This commit is contained in:
Ryan Peters 2023-05-12 12:47:54 -04:00
parent b60a246c34
commit faaa0dba8f
3 changed files with 16 additions and 0 deletions

View File

@ -24,4 +24,12 @@ public class HomeController : Controller
return View(model); return View(model);
} }
[Route("{noteName}/delete")]
public IActionResult Delete(string noteName)
{
noteService.DeleteNote(noteName);
return Redirect("/");
}
} }

View File

@ -32,6 +32,13 @@
File.WriteAllText(GetFilePath(noteName), content); File.WriteAllText(GetFilePath(noteName), content);
} }
public void DeleteNote(string noteName)
{
var filePath = GetFilePath(noteName);
File.Delete(filePath);
}
private void CheckFile(string noteName) private void CheckFile(string noteName)
{ {
var filePath = GetFilePath(noteName); var filePath = GetFilePath(noteName);

View File

@ -5,5 +5,6 @@
ICollection<string> GetNoteNames(); ICollection<string> GetNoteNames();
string GetText(string? noteName); string GetText(string? noteName);
void SaveText(string content, string? noteName); void SaveText(string content, string? noteName);
void DeleteNote(string noteName);
} }
} }