Browse Source

API for deleting documents

master
Lynne Megido 1 month ago
parent
commit
107fe6078c
Signed by: lynnesbian GPG Key ID: F0A184B5213D9F90
2 changed files with 18 additions and 1 deletions
  1. +17
    -0
      Controllers/DocumentController.cs
  2. +1
    -1
      Pages/Upload.cshtml.cs

+ 17
- 0
Controllers/DocumentController.cs View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Snootalogue.Models;
@ -30,5 +31,21 @@ namespace Snootalogue.Controllers {
return document;
}
[HttpDelete("{id}")]
public async Task<ActionResult<bool>> DeleteDocument(string id) {
var document = await _context.Document.FindAsync(id);
if (document == null) {
return NotFound();
}
var uploadDirectory = Path.Combine("wwwroot", "Content");
var destination = Path.Combine(uploadDirectory, $"{id}.pdf");
System.IO.File.Delete(destination);
_context.Remove(document);
await _context.SaveChangesAsync();
return true;
}
}
}

+ 1
- 1
Pages/Upload.cshtml.cs View File

@ -34,7 +34,7 @@ namespace Snootalogue.Pages {
var id = Document.NewID(_context);
// var uploadDirectory = Path.Combine(filename);
var uploadDirectory = "wwwroot/Content";
var uploadDirectory = Path.Combine("wwwroot"</span>, "Content");
var destination = Path.Combine(uploadDirectory, $"{id}.pdf");
using (var fs = new FileStream(destination, FileMode.Create)) {

Loading…
Cancel
Save