I have a feeling this is probably something simple and I'm going to smack myself in the head when I figure it out, but I am stuck on how to call another action within my controller. What I am trying to do is send an email as an attachment when an order form is submitted. I have the email working perfectly, but am now trying to figure out how to get the attachment to work. I've read that Rotativa is the easiest way to generate a pdf so I'm using that. I have an action method in my controller that works great, but the problem is I can't figure out how to call that action in the other action method I'm using. Here is my code so far in my controller, I took out the stuff that's not applicable:
private ActionResult AttachFile(int? id)
{
string orderNum = "FulfillmentOrder" + id.ToString() + ".pdf";
return new ActionAsPdf("OrderDetailsReport", new { id = id }) { FileName = orderNum };
}
public ActionResult ProcessOrder(int? id)
{
//Send confirmation email
var msgTitle = "Order Confirmation #" + orderDetail.OrderID;
var recipient = JohnDoe;
var fileAttach = //This is where I'd like to call the action above//
var fileList = new string[] { fileAttach };
var errorMessage = "";
var OrderConfirmation = "Your order has been placed and is pending review." +
" Attached is a copy of your order.";
try
{
// Initialize WebMail helper
WebMail.SmtpServer = "abc.net";
WebMail.SmtpPort = 555;
WebMail.UserName = recipient;
WebMail.Password = "12345";
WebMail.From = "orders@samplecode.com";
// Send email
WebMail.Send(to: "orders@samplecode.com",
subject: msgTitle,
body: OrderConfirmation,
filesToAttach: fileList
);
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
}
Maybe how I'm trying to do it won't work, I'm open to any suggestions that may be more efficient, but I want to make the pdf generated attach to the email. It seems like if I can call that private action somehow on the "var fileAttach" line it would work. Lastly, the code above are both in the same controller. Thank you for any help on this!