Exemplo n.º 1
0
        // GET: Admin/PrintApptLtr/5
        public ActionResult PrintApptLtr(int id)
        {
            ConsularApptVM model = EmbassyAppDb.GetConsularApptById(id);

            AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(model.AppointmentType);
            string          pdfTemplateFile = ConfirmationLetterPdf.GetPdfTemplateFileName(appointmentType, model.StayType);
            MemoryStream    pdfStream       = ConfirmationLetterPdf.GetAppointmentLetterStream(pdfTemplateFile, model);

            //string confirmationLetter = this.GetConfirmationLetter(id);
            //MemoryStream pdfStream = new MemoryStream();
            //Pdf.WriteHtmlToPdfStream(confirmationLetter, pdfStream);

            return(new FileStreamResult(pdfStream, "application/pdf"));
        }
Exemplo n.º 2
0
        // GET: Admin/PrintApptLtr/5
        public ActionResult PrintApptLtr(int id)
        {
            ConsularApptVM model = DpWebAppDb.GetConsularApptById(id);

            AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(model.AppointmentType);
            string          pdfTemplateFile = DpWebAppConfig.CnslrLtrPdfTmplPath + appointmentType.ConsularLtrPdfTmplFilename;
            MemoryStream    pdfStream       = ConfirmationLetterPdf.GetAppointmentLetterStream(pdfTemplateFile, model);

            //string confirmationLetter = this.GetConfirmationLetter(id);
            //MemoryStream pdfStream = new MemoryStream();
            //Pdf.WriteHtmlToPdfStream(confirmationLetter, pdfStream);

            return(new FileStreamResult(pdfStream, "application/pdf"));
        }
Exemplo n.º 3
0
 private static void SetViewBagForConfirmationLetter(this Controller cntlr, ConsularApptVM consularApptVM)
 {
     if (cntlr.ViewBag.Logo == null)
     {
         string basePath = AppDomain.CurrentDomain.BaseDirectory;
         cntlr.ViewBag.Logo = Graphics.GetImgSrcForPdf(basePath + DpWebAppConfig.Emblem_Logo);
     }
     // Get Service Type look up
     if (cntlr.ViewBag.AppointmentType == null)
     {
         AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(consularApptVM.AppointmentType);
         cntlr.ViewBag.AppointmentType = appointmentType.Description;
     }
     // Get QR code
     if (cntlr.ViewBag.QR == null)
     {
         cntlr.ViewBag.QR = Graphics.GenerateRelayQrCode(ConfirmationLetterPdf.GetQrCodeString(consularApptVM));
     }
 }
Exemplo n.º 4
0
        public async Task <ActionResult> ConfirmPosted(string confirmedId, string confirmedCode)
        {
            if (!Request.IsAjaxRequest())
            {
                return(Content("Request Error."));
            }

            int    id   = int.Parse(confirmedId);
            string code = confirmedCode;

            DateTime?      confirmedApptDate  = null;
            int?           confirmedQueNumber = 0;
            ConsularApptVM consularApptVM     = EmbassyAppDb.ConfirmConsularAppt(id, code, ref confirmedApptDate, ref confirmedQueNumber);

            if (consularApptVM == null)
            {
                return(RedirectToAction("Error"));
            }

            string confirmedEmailBody = this.GetConfirmedEmailBody(consularApptVM);
            string confirmationLetter = this.GetConfirmationLetter(consularApptVM);
            // To do: Maybe convert the confirmationLetter to PDF, or get fillable PDF letter

            // Get Required Form Attachment List
            AppointmentType       appointmentType = ConsularAppointmentTypes.GetAppointmentType(consularApptVM.AppointmentType);
            List <BLL.Attachment> formAttachments = appointmentType.Attachments?.List;

            // Start preparing for Email
            Email embassyMail = new Email
            {
                From        = EmWebAppConfig.EmailAddress,
                DisplayName = EmWebAppConfig.EmailUser,
                To          = consularApptVM.ContactEmail,
                Subject     = EmWebAppConfig.EmailSubj_Confirmed,
                Body        = confirmedEmailBody,
                IsHtml      = true
            };

            // using (MemoryStream ms = new MemoryStream())
            string pdfTemplateFile = ConfirmationLetterPdf.GetPdfTemplateFileName(appointmentType, consularApptVM.StayType);

            using (MemoryStream ms = ConfirmationLetterPdf.GetAppointmentLetterStream(pdfTemplateFile, consularApptVM))
                using (MailMessage mailMsg = embassyMail.Message)
                    using (var smtp = new SmtpClient())
                    {
                        System.Net.Mail.Attachment coverLetterPdf = Email.GetPdfAttachmentFromPdfStream(ms, "AppointmentLetter.pdf");
                        // System.Net.Mail.Attachment coverLetterPdf = Email.GetPdfAttachmentFromHtmlString(confirmationLetter, ms, "AppointmentLetter.pdf");
                        mailMsg.Attachments.Add(coverLetterPdf);

                        if (formAttachments != null)
                        {
                            foreach (var attachment in formAttachments)
                            {
                                if (System.IO.File.Exists(attachment.FullPath))
                                {
                                    var emailAttachment = new System.Net.Mail.Attachment(attachment.FullPath, new ContentType(MediaTypeNames.Application.Pdf));
                                    mailMsg.Attachments.Add(emailAttachment);
                                }
                            }
                        }

                        smtp.Prep();
                        await smtp.SendMailAsync(mailMsg);

                        // return View(consularApptVM);
                        return(PartialView("_MsgApptConfirmed", consularApptVM));
                    }
        }