public async Task <string> UploadDocument(string clientId, string type, string fileName, string mime, byte[] data) { var kycDocument = await _kycDocumentsRepository.AddAsync(KycDocument.Create(clientId, type, mime, fileName)); await _kycDocumentsScansRepository.AddDocument(kycDocument.DocumentId, data); await _kycUploadsLog.AddAsync(KycUploadsLogItem.Create(clientId, type, kycDocument.DocumentId, mime)); return(kycDocument.DocumentId); }
public async Task <OperationResponse> UploadDocument(UploadDocumentRequest request) { try { _logger.LogInformation("Uploading documents with type {type} for client {clientId}", request.Type, request.ClientId); var profile = await _repository.GetOrCreateProfile(request.ClientId); if (string.IsNullOrEmpty(profile.ApplicantId)) { _logger.LogInformation("Creating applicant id for client {clientId}", request.ClientId); profile.ApplicantId = await _httpService.CreateApplicantId(request.ClientId); await _repository.UpdateProfile(profile, "Created applicant id", "automatic", null); } var existingDocumentId = profile.Documents.FirstOrDefault(t => t.Type == request.Type)?.DocumentId; var(documentId, file1, file2) = await _httpService.UploadDocument(profile.ApplicantId, request.FileSide1, request.FileSide2, request.Type, request.FileType, existingDocumentId); await using var context = new DatabaseContext(_dbContextOptionsBuilder.Options); var document = new KycDocument() { DocumentId = documentId, ClientId = profile.ClientId, Type = request.Type, FileId1 = file1, FileId2 = file2, Verified = false, DeclineReason = string.Empty }; await context.UpsertAsync(new[] { document }); context.AuditLogs.Add(KycAuditLog.Create(document, "Document upload", "automatic", null)); await context.SaveChangesAsync(); return(new OperationResponse() { IsSuccess = true }); } catch (Exception e) { _logger.LogError(e, "When uploading document for clientId {clientId}", request.ClientId); return(new OperationResponse() { IsSuccess = false, Error = e.Message }); } }
public async Task <string> UploadDocument(string clientId, string type, string fileName, string mime, byte[] data, string changer) { var documentBeforeTask = _kycDocumentsRepository.GetAsync(clientId); var kycDocument = await _kycDocumentsRepository.AddAsync(KycDocument.Create(clientId, type, mime, fileName)); await _kycDocumentsScansRepository.AddDocument(kycDocument.DocumentId, data); await UpdateKycProfileSettings(clientId); var documentBefore = (await documentBeforeTask)? .OrderByDescending(x => x.DateTime) .FirstOrDefault(x => x.Type == type); await _auditLogRepository.AddAuditRecordAsync(clientId, documentBefore, kycDocument, AuditRecordType.KycDocument, changer); return(kycDocument.DocumentId); }