private async Task <Batch> ProcessFile(PrintFileInfo fileInfo) { var receipt = JsonConvert.DeserializeObject <PrintReceipt>(fileInfo.FileContent); if (receipt?.Batch == null || receipt.Batch.BatchDate == DateTime.MinValue) { fileInfo.InvalidFileContent = fileInfo.FileContent; throw new FileFormatValidationException($"Could not process print response file [{fileInfo.FileName}] due to invalid file format"); } var batch = await _batchService.Get(receipt.Batch.BatchNumber); if (batch == null) { fileInfo.InvalidFileContent = fileInfo.FileContent; throw new FileFormatValidationException($"Could not process print response file [{fileInfo.FileName}] due to non matching Batch Number [{receipt.Batch.BatchNumber}]"); } batch.BatchCreated = receipt.Batch.BatchDate; batch.NumberOfCoverLetters = receipt.Batch.PostalContactCount; batch.NumberOfCertificates = receipt.Batch.TotalCertificateCount; batch.PrintedDate = receipt.Batch.ProcessedDate; batch.DateOfResponse = DateTime.UtcNow; batch.Status = CertificateStatus.Printed; batch.Certificates = await _batchService.GetCertificatesForBatchNumber(batch.BatchNumber); return(batch); }