public IActionResult Get(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); var result = facade.ReadModelById(id); PurchasingDispositionViewModel viewModel = mapper.Map <PurchasingDispositionViewModel>(result); if (viewModel == null) { throw new Exception("Invalid Id"); } if (indexAcceptPdf < 0) { return(Ok(new { apiVersion = ApiVersion, statusCode = General.OK_STATUS_CODE, message = General.OK_MESSAGE, data = viewModel, })); } else { int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); PurchasingDispositionPDFTemplate PdfTemplate = new PurchasingDispositionPDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel, clientTimeZoneOffset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{result.DispositionNo}.pdf" }); } //Dictionary<string, object> Result = // new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE) // .Ok(viewModel); //return Ok(Result); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public IActionResult GetPDF(int id) { try { var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf"); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; PurchasingDisposition model = facade.ReadModelById(id); PurchasingDispositionViewModel viewModel = mapper.Map <PurchasingDispositionViewModel>(model); if (indexAcceptPdf < 0) { return(Ok(new { apiVersion = ApiVersion, statusCode = General.OK_STATUS_CODE, message = General.OK_MESSAGE, data = viewModel, })); } else { int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First()); PurchasingDispositionPDFTemplate PdfTemplate = new PurchasingDispositionPDFTemplate(); MemoryStream stream = PdfTemplate.GeneratePdfTemplate(viewModel, clientTimeZoneOffset); return(new FileStreamResult(stream, "application/pdf") { FileDownloadName = $"{model.DispositionNo}.pdf" }); } } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }