private async Task ScheduleIndexing(DocumentUploadDto documentDto, CancellationToken cancellationToken) { using (var context = applicationDbContextFactory.Create()) { using (var transaction = await context.Database.BeginTransactionAsync()) { bool.TryParse(documentDto.IsOcrRequested, out var isOcrRequest); var document = new Document { Title = documentDto.Title, Filename = documentDto.File.FileName, Suggestions = GetSuggestions(documentDto.Suggestions), Keywords = GetSuggestions(documentDto.Suggestions), Data = await GetBytesAsync(documentDto.File), IsOcrRequested = isOcrRequest, UploadedAt = DateTime.UtcNow, Status = StatusEnum.ScheduledIndex }; context.Documents.Add(document); await context.SaveChangesAsync(cancellationToken); await transaction.CommitAsync(); } } }
public async Task <IActionResult> IndexDocument([FromForm] DocumentUploadDto documentDto, CancellationToken cancellationToken) { try { await ScheduleIndexing(documentDto, cancellationToken); return(Ok()); } catch (Exception e) { logger.LogError(e, "Failed to schedule document for Indexing"); return(StatusCode(500)); } }
public async Task UploadAsync(DocumentUploadDto uploadDto) { var fileId = await amazonService.UploadFileAsync(uploadDto.Name); await documentRepo.CreateAsync(fileId, uploadDto.Name, uploadDto.Creator, uploadDto.Created); }
public async Task Upload([FromBody] DocumentUploadDto document) { document.Creator = Guid.Parse(LoggedUserId); document.Created = DateTime.UtcNow; await this.documentService.UploadAsync(document); }