public virtual IActionResult BatchReportIdDeletePost([FromRoute] int id) { bool exists = _context.HetBatchReport.Any(a => a.ReportId == id); // not found if (!exists) { return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); } HetBatchReport report = _context.HetBatchReport.First(a => a.ReportId == id); if (report != null) { _context.HetBatchReport.Remove(report); // delete file FileUtility.DeleteFile(report.ReportLink); // save the changes _context.SaveChanges(); } return(new ObjectResult(new HetsResponse(report))); }
public virtual IActionResult BatchReportIdDownloadGet([FromRoute] int id) { bool exists = _context.HetBatchReport.Any(a => a.ReportId == id); // not found if (!exists) { return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); } HetBatchReport report = _context.HetBatchReport.AsNoTracking().First(a => a.ReportId == id); // report name string reportName = report.ReportName + ".pdf"; // get binary byte[] reportBinary = FileUtility.FileToByteArray(report.ReportLink); // return content FileContentResult result = new FileContentResult(reportBinary, "application/pdf") { FileDownloadName = reportName }; Response.Headers.Add("Content-Disposition", "inline; filename=" + reportName); return(result); }