public async Task <IActionResult> OnGetInvoicePDFAsync(int id, long invoiceId) { var fileName = string.Format(_settings.InvoiceGroceryNameFormat, id); //Check if file already exist if (_service.CheckIfFileExists(_settings.InvoicesFolderFullPath, fileName)) { byte[] fileBytes = await System.IO.File.ReadAllBytesAsync( Path.Combine( _settings.InvoicesFolderFullPath, fileName)); return(File(fileBytes, "application/pdf")); } else { var bytes = await _service.GetInvoicePDFAsync(ApplicationCore.Entities.SageApplicationType.SALESWEB, invoiceId); if (bytes.Length > 0) { await _service.SaveFileAsync(bytes, _settings.InvoicesFolderFullPath, fileName); } return(File(bytes, "application/pdf", fileName)); } }
public async Task <IActionResult> OnGetAsync(int id) { OrderModel = await _service.GetOrder(id); if (OrderModel == null) { return(NotFound()); } var fileName = string.Format(_settings.InvoiceNameFormat, id); OrderModel.HasInvoiceReady = _service.CheckIfFileExists(_settings.InvoicesFolderFullPath, fileName); return(Page()); }