I have a controller action which generates and streams a PDF to the client, but would also like to have a controller action which emails the output of that PDF download action as an attachment. I know how to send an email, the question is how can I use/capture that MVC download action for my email attachment.
Pseudo code:
public PdfResult Download(int? someId)
{
var pdfBuilder = new pdfBuilder();
var pdfStream = pdfBuilder.StreamPdf(someId);
return new PdfResult("someId.pdf", "application/pdf", pdfStream);
}
public ActionResult Email(int? someId)
{
var pdfStream = View("Download", someId);
var attachment = new Attachment(pdfStream, "someId.pdf");
//...send email code
}
PdfBuilderof yours, why don't you just call it again when sending the email...? And if you don't want to duplicate code, just refactor the pdf generation code into a third method.