コード例 #1
0
        public void ExportarPdf()
        {
            try
            {
                //consultar as contas no banco de dados..
                var contas = unitOfWork.ContaRepository.GetAll()
                             .OrderByDescending(c => c.DataConta)
                             .ToList();

                var totalReceitas = contas
                                    .Where(c => c.Categoria.Nome.ToUpper()
                                           .Contains("RECEITA"))
                                    .Sum(c => c.ValorConta);

                var html = ContaHtmlReport.GetReport(contas);

                var pdf = PdfReport.Convert(html);

                //DOWNLOAD DO PDF..
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.Headers.Add("content-disposition", "attachment; filename=contas.pdf");
                Response.Body.WriteAsync(pdf, 0, pdf.Length);
                Response.Body.Flush();
                Response.StatusCode = StatusCodes.Status200OK;
            }
            catch (Exception e)
            {
                TempData["MensagemErro"] = e.Message;
            }
        }