// 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")); }
// 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")); }
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)); } }