Ejemplo n.º 1
0
        public IHttpActionResult GetDownload(int id)
        {
            /* Get Invoice PDF */
            Invoice             invoice     = UnitOfWork.Invoices.Get(id);
            PDFInvoice          pdf         = new PDFInvoice(invoice);
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);

            pdfRenderer.Document = pdf.CreateDocument();
            pdfRenderer.RenderDocument();
            MemoryStream stream = new MemoryStream();

            pdfRenderer.Save(stream, false);

            /* Send PDF file */
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(stream)
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            var response = ResponseMessage(result);

            return(response);
        }
Ejemplo n.º 2
0
        public static void SendEmail(Invoice invoice, string from, string emailTo)
        {
            string      subject  = "Invoice - " + invoice.InvoiceNo;
            string      body     = "Hi," + Environment.NewLine + "Invoice file in attachment.";
            string      FromMail = from + "@billing.com";
            MailMessage mail     = new MailMessage();

            mail.From = new MailAddress(FromMail);
            mail.To.Add(emailTo);
            mail.Subject = subject;
            mail.Body    = body;

            PDFInvoice pdf = new PDFInvoice(invoice);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);

            pdfRenderer.Document = pdf.CreateDocument();

            pdfRenderer.RenderDocument();


            MemoryStream stream = new MemoryStream();

            pdfRenderer.Save(stream, false);



            mail.Attachments.Add(new Attachment(stream, "Invoice-" + DateTime.UtcNow.ToShortDateString() + ".pdf", MediaTypeNames.Application.Pdf));


            SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["SmtpClient"]);

            SmtpServer.Port        = 25;
            SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Email"], ConfigurationManager.AppSettings["EmailPassword"]);
            SmtpServer.EnableSsl   = true;
            SmtpServer.Send(mail);
        }