private async Task <Invoice> Invoice(Order order) { Invoice invoice = await _invoiceGen.Generate(order); await _invoiceRepo.Save(invoice); return(invoice); }
public async Task <IActionResult> GetInvoice([FromRoute] int id) { var order = orderRepository.GetById(id); if (order == null) { return(NotFound()); } var invoiceText = await invoiceGenerator.Generate(order); if (invoiceText == null) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(Ok(invoiceText)); }
/// <summary> /// Concurrently generates invoice files using instance of <see cref="IInvoiceGenerator`1"/>. /// </summary> public void GenerateInvoices() { var exceptions = new ConcurrentQueue <Exception>(); //generates all PDF invoices concurrently Parallel.ForEach(generatedOrders, order => { try { invoiceGenerator.Generate(order); } catch (Exception e) { exceptions.Enqueue(e); } }); if (exceptions.Count > 0) { throw new AggregateException(exceptions); } }