API for deleting documents
This commit is contained in:
parent
e5748ec8d5
commit
107fe6078c
2 changed files with 18 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.IO;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Snootalogue.Models;
|
using Snootalogue.Models;
|
||||||
|
@ -30,5 +31,21 @@ namespace Snootalogue.Controllers {
|
||||||
|
|
||||||
return document;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace Snootalogue.Pages {
|
||||||
|
|
||||||
var id = Document.NewID(_context);
|
var id = Document.NewID(_context);
|
||||||
// var uploadDirectory = Path.Combine(filename);
|
// var uploadDirectory = Path.Combine(filename);
|
||||||
var uploadDirectory = "wwwroot/Content";
|
var uploadDirectory = Path.Combine("wwwroot", "Content");
|
||||||
var destination = Path.Combine(uploadDirectory, $"{id}.pdf");
|
var destination = Path.Combine(uploadDirectory, $"{id}.pdf");
|
||||||
|
|
||||||
using (var fs = new FileStream(destination, FileMode.Create)) {
|
using (var fs = new FileStream(destination, FileMode.Create)) {
|
||||||
|
|
Loading…
Reference in a new issue