Project :PRL glass
Ticket 102771: [PRL Glass] 3.3. Download Customer Statement report from My Account
Response.SetCookie(new HttpCookie("fileDownload", "true") { HttpOnly = false });
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline; filename=" + reportname + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.OutputStream.Write(memoryStreamReport, 0, memoryStreamReport.Length);
Response.End();
View\Default\Profile\Index.cshtml
// Ticket 102771: [PRL Glass] 3.3. Download Customer Statement report from My Account
// Add Button with and set target = "_blank" to open in new window.
@Sana.LinkButton(textKey: reportName.ToString(),
url: Url.Action("CustomerStatmentReport", "ErpFileDownload", new { customerId = customerId.ToString() }),
cssClass: "btn btn-report", defaultText: reportName.ToString(), htmlAttributes: new { rel = "nofollow", target = "_blank" })
public class ExtendedErpFileDownloadController : ErpFileDownloadController
{
protected override void RegisterSystemRoutes(SanaRouteCollection routes)
{
base.RegisterSystemRoutes(routes);
// Ticket 102771: [PRL Glass] 3.3. Download Customer Statement report from My Account
routes.MapSystemPageRoute(Name, "CustomerStatmentReport", "CustomerStatmentReport", "CustomerStatmentReport/files/Customer-Statment-Report.pdf");
}
// Ticket 102771: [PRL Glass] 3.3. Download Customer Statement report from My Account
/// <summary>
/// A GET action to get the customer statment report.
/// </summary>
/// <param name="customerId">The customer ID.</param>
/// <returns>Returns the order report.</returns>
[Authorize]
[HttpGet]
public virtual ActionResult CustomerStatmentReport(string customerId, int maxTimeoutExceptionSkips = 5, int sleepDurationBetweenAttempts = 10000)
{
if (customerId.IsEmptyString())
return HttpNotFound();
Stream reportStream = null;
var retryCount = maxTimeoutExceptionSkips;
while (true)
{
try
{
reportStream = ((ExtendedAttachmentApi)ShopApi.Attachments).LoadCustomerStatmentReport(customerId);
}
catch (SanaConnectionException ex)
{
if (ex.InnerException == null || !(ex.InnerException is TimeoutException))
throw;
if (retryCount == 0)
throw;
Thread.Sleep(sleepDurationBetweenAttempts);
retryCount--;
continue;
}
break;
}
if (reportStream == null)
return new HttpNotFoundResult();
//Set report name.
var reportname = "CustomerStatmentReport_" + customerId;
//Get bytes from stream.
var memoryStreamReport = ((MemoryStream)reportStream).ToArray();
Response.SetCookie(new HttpCookie("fileDownload", "true") { HttpOnly = false });
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline; filename=" + reportname + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.OutputStream.Write(memoryStreamReport, 0, memoryStreamReport.Length);
Response.End();
return File(reportStream, System.Net.Mime.MediaTypeNames.Application.Pdf, reportname);
}
}