public async Task <IActionResult> AddFileDocument([FromRoute] long id) { try { var file = Request.Form.Files[0]; var fileDocumentFactory = new FileDocumentFactory(file, _hostingEnvironment); var document = fileDocumentFactory.CreateDocument(); Registry registry = _context.Registries.First(i => i.RegistryID == id); registry.Documents.Add(document); _context.Entry(registry).State = EntityState.Modified; _context.SaveChanges(); var response = await _context.Documents.SingleOrDefaultAsync(m => m.DocumentID == document.DocumentID); if (response == null) { return(NotFound()); } return(Ok(response)); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Registers a factory method for loading documents of the given file extension. By default, a corpus /// does not know how to load any files -- this method must be called prior to GetDocuments(). /// </summary> public void RegisterFileDocumentFactory(string fileExtension, FileDocumentFactory factory) { mFactories[fileExtension] = factory; }