public DocFileDto GetDocument(int id) { var documentEntity = _fileDBContext.DocFile.Where(d => d.Id == id).FirstOrDefault(); var document = new DocFileDto() { Id = documentEntity.Id, Location = documentEntity.Location, Filesize = documentEntity.Filesize, Name = documentEntity.Name, Content = documentEntity.Content }; return(document); }
public async Task <DocFileDto> CreateDocumentAsync(DocFileDto document) { //Would use Automapper without time constraints var documentEntity = new DocFile() { Id = document.Id, Location = document.Location, Filesize = document.Filesize, Name = document.Name, Content = document.Content }; _fileDBContext.DocFile.Add(documentEntity); var docKey = await _fileDBContext.SaveChangesAsync(); document.Id = docKey; return(document); }
public async Task <IActionResult> Upload(IFormFile file) { var extension = Path.GetExtension(file.FileName); if (!(file == null)) { //Neither the MIME type nor the file extension is reliable information to determine //the file type - both can be easily changed. if (extension.ToLower() != ".pdf") { return(BadRequest("Non PDF file type")); } if (file.Length > (5 * 1024 * 1024)) { return(BadRequest("5MB file upload limit")); } } if (file.Length > 0) { using var stream = new MemoryStream(); await file.CopyToAsync(stream); if (stream.Length < 2097152) { var docDto = new DocFileDto() { Name = file.FileName, Content = stream.ToArray() }; await _documentService.CreateDocumentAsync(docDto); } } return(Ok()); }