public async Task <IActionResult> GetById([FromRoute] int id) { try { var accept = Request.Headers["Accept"]; if (accept == "application/pdf") { VerifyUser(); var result = await _service.ReadPdfById(id); return(File(result.Data.ToArray(), "application/pdf", result.FileName)); } else if (accept == "application/xls") { VerifyUser(); var result = await _service.ReadExcelById(id); return(File(result.Data.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", result.FileName)); } var data = await _service.ReadById(id); return(Ok(new { data })); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <IActionResult> GetPDF([FromRoute] int Id, [FromRoute] string type) { if (!ModelState.IsValid) { var exception = new { error = ResultFormatter.FormatErrorMessage(ModelState) }; return(new BadRequestObjectResult(exception)); } try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); int timeoffsset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); var model = await _service.ReadById(Id); if (model == null) { return(StatusCode((int)HttpStatusCode.NotFound, "Not Found")); } else { Buyer buyer = _service.GetBuyer(model.BuyerAgent.Id); BankAccount bank = _service.GetBank(model.BankAccountId); GarmentPackingListViewModel pl = await _packingListService.ReadById(model.PackingListId); if (type == "fob") { var PdfTemplate = new GarmentShippingInvoicePdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, buyer, bank, pl, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.InvoiceNo + "-Invoice" + ".pdf" }); } else { var PdfTemplate = new GarmentShippingInvoiceCMTPdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, buyer, bank, pl, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = model.InvoiceNo + "-CMT" + ".pdf" }); } } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <IActionResult> GetPDF([FromRoute] int Id) { if (!ModelState.IsValid) { var exception = new { error = ResultFormatter.FormatErrorMessage(ModelState) }; return(new BadRequestObjectResult(exception)); } try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); int timeoffsset = Convert.ToInt32(Request.Headers["x-timezone-offset"]); var model = await _service.ReadById(Id); if (model == null) { return(StatusCode((int)HttpStatusCode.NotFound, "Not Found")); } else { GarmentShippingInvoiceViewModel invoice = await _invoiceService.ReadById(model.InvoiceId); GarmentPackingListViewModel pl = await _packingListService.ReadById(invoice.PackingListId); GarmentCoverLetterViewModel cl = await _coverletterService.ReadByInvoiceId(invoice.Id); var PdfTemplate = new GarmentShippingInstructionPdfTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, cl, pl, invoice, timeoffsset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = "Shipping Instruction - " + model.InvoiceNo + ".pdf" }); } } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }