public byte[] GenerateLetter(VisaLetter visaLetter) { var doc = InitializeDocument(); var ms = new MemoryStream(); var writer = PdfWriter.GetInstance(doc, ms); //This binds the memory stream to the doc. doc.Open(); var table = InitializeTable(); WriteHeader(table, doc); #region Date Approved table = InitializeTable(2); table.SetWidths(new float[] { 61, 39 }); //table.AddCell(InitializeCell(halignment: Element.ALIGN_RIGHT, bottomBorder: false, overridePaddingTop: 5, overridePaddingBottom: 20)); table.AddCell(InitializeCell(bottomBorder: false, font: _smallPrint, padding: false)); doc.Add(table); #endregion Date Approved table = InitializeTable(); table.AddCell(InitializeCell(visaLetter.DateDecided.HasValue ? visaLetter.DateDecided.Value.Date.ToString("MMMM dd, yyyy") : DateTime.UtcNow.ToPacificTime().Date.ToString("MMMM dd, yyyy"), halignment: Element.ALIGN_LEFT, bottomBorder: false, overridePaddingTop: 5, overridePaddingBottom: 20)); table.AddCell(InitializeCell("To Whom It May Concern", halignment: Element.ALIGN_LEFT, bottomBorder: false, overridePaddingBottom:25)); table.AddCell(InitializeCell(string.Format("RE: {0} {1} Request for Visa", visaLetter.StudentFirstName, visaLetter.StudentLastName), halignment: Element.ALIGN_LEFT, bottomBorder: false, overridePaddingBottom:10)); table.AddCell(InitializeCell(string.Format("{0} {1} is completing {2} requirements for a {3} degree in {4}. {5} is participating in the College of {6}’s commencement ceremony held at the UC Davis campus in Davis, California, United States of America on {7}." , visaLetter.StudentFirstName //0 , visaLetter.StudentLastName //1 , visaLetter.Gender == "M" ? "his" : "her" //2 , visaLetter.Degree //3 , visaLetter.MajorName //4 , visaLetter.Gender == "M" ? "He" : "She" //5 , visaLetter.CollegeName //6 , visaLetter.CeremonyDateTime.HasValue ? visaLetter.CeremonyDateTime.Value.Date.ToString("MMMM dd, yyyy") : "ERROR") //7 , halignment: Element.ALIGN_LEFT, bottomBorder: false)); table.AddCell(InitializeCell(string.Format("{0} {1} would be extremely appreciative if {2} {3}, {4} {5} could attend the ceremony. {6}. {4} {5} resides at:" , visaLetter.Gender == "M" ? "Mr." : "Ms." //0 , visaLetter.StudentLastName //1 , visaLetter.Gender == "M" ? "his" : "her" //2 , visaLetter.RelationshipToStudent //3 , visaLetter.RelativeFirstName //4 , visaLetter.RelativeLastName //5 , visaLetter.RelativeTitle //6 ) , halignment: Element.ALIGN_LEFT, bottomBorder: false)); table.AddCell(InitializeCell(visaLetter.RelativeMailingAddress, halignment: Element.ALIGN_LEFT, bottomBorder: false, overridePaddingBottom: 10)); table.AddCell(InitializeCell(string.Format("This is a memorable occasion and we hope that {0}. {1} {2} can attend." , visaLetter.RelativeTitle //0 , visaLetter.RelativeFirstName //1 , visaLetter.RelativeLastName //2 ), halignment: Element.ALIGN_LEFT, bottomBorder: false)); WriteSignature(visaLetter, table, doc); // doc.Add(table); WriteFooter(visaLetter, writer); doc.Close(); return ms.ToArray(); }
private Ceremony GetCeremonyForVisaLetter(VisaLetter letter, bool useDefaultCeremony = false) { var termCode = TermService.GetCurrent(); var currentReg = _registrationRepository.Queryable.SingleOrDefault(a => a.Student == letter.Student && a.TermCode.Id == termCode.Id); // has this student registered yet? if (currentReg != null) { // display previous registration var participation = currentReg.RegistrationParticipations.FirstOrDefault(a => !a.Cancelled && !a.Registration.Student.SjaBlock && !a.Registration.Student.Blocked); if (participation != null && participation.Ceremony.Colleges.Any(a => a.Id == letter.CollegeCode)) { return participation.Ceremony; } } if (useDefaultCeremony) //So we can grab a template. But we don't want to use this for defaulting the date { return Repository.OfType<Ceremony>().Queryable.FirstOrDefault(a => a.Id == 1); } return null; }
private void WriteFooter(VisaLetter visaLetter, PdfWriter writer) { var ct = new ColumnText(writer.DirectContent); Phrase myText = new Phrase(string.Format("Letter Id: {0}", visaLetter.ReferenceGuid), _smallPrint); ct.SetSimpleColumn(myText, 0, 50, _pageWidth + 40, 0, 0, Element.ALIGN_RIGHT); ct.Go(); }
private void WriteSignature(VisaLetter visaLetter, PdfPTable table, Document doc) { string url; Image img; var user = _repository.OfType<vUser>().Queryable.FirstOrDefault(a => a.LoginId == visaLetter.ApprovedBy); Check.Require(user != null, "Approval User is required"); var cell = InitializeCell("Should you need more information, please contact me at ", halignment: Element.ALIGN_LEFT, bottomBorder: false); var anchor = new Anchor(user.Email, _linkFont); anchor.Reference = string.Format("mailto:{0}", user.Email); cell.Phrase.Add(anchor); table.AddCell(cell); doc.Add(table); table = InitializeTable(2); table.SetWidths(new float[]{40,60}); table.AddCell(InitializeCell("", halignment: Element.ALIGN_LEFT, bottomBorder: false, overridePaddingTop: 20)); table.AddCell(InitializeCell("Kind regards.", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 20)); url = HttpContext.Current.Server.MapPath(string.Format("~/Images/vl_{0}_signature.png", user.LoginId.ToLower().Trim())); if (File.Exists(url)) { img = Image.GetInstance(new Uri(url)); img.ScaleToFit(140f, 40f); } else { throw new Exception("Image not found " + url); } var imageCell = new PdfPCell(img); imageCell.BorderWidthLeft = 0; imageCell.BorderWidthRight = 0; imageCell.BorderWidthTop = 0; imageCell.BorderWidthBottom = 0; imageCell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(InitializeCell("", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false)); table.AddCell(imageCell); // (InitializeCell(img, halignment: Element.ALIGN_RIGHT, bottomBorder: false)); table.AddCell(InitializeCell("", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false)); table.AddCell(InitializeCell(user.FullName, halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false)); table.AddCell(InitializeCell("", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 0)); table.AddCell(InitializeCell("Commencement Coordinator", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 0)); table.AddCell(InitializeCell("", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 0)); table.AddCell(InitializeCell("UC Davis", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 0)); table.AddCell(InitializeCell("", halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 0)); table.AddCell(InitializeCell(user.Phone, halignment: Element.ALIGN_LEFT, bottomBorder: false, padding: false, overridePaddingTop: 0)); doc.Add(table); }
public string GenerateVisaLetterRequestDecision(VisaLetter visaLetter, Template template, HttpRequestBase request, UrlHelper url) { _ceremony = new Ceremony(); //Don't care about ceremony _student = visaLetter.Student; _registration = new Registration(); //Don't Need _template = template; _visaLetter = visaLetter; _request = request; _url = url; return HandleBody(template.BodyText); }
public static AdminVisaDetailsModel Create(VisaLetter visaLetter, List<VisaLetter> relatedLetters) { var viewModel = new AdminVisaDetailsModel() {VisaLetter = visaLetter, RelatedLetters = relatedLetters}; return viewModel; }
public ActionResult RequestVisaLetter(VisaLetterPostModel model) { // validate student is in our DB, otherwise we need to do a lookup var student = GetCurrentStudent(); // we were just unable to find record if (student == null) return this.RedirectToAction<ErrorController>(a => a.NotFound()); var existingLetter = Repository.OfType<VisaLetter>().Queryable.FirstOrDefault(a => a.Student.StudentId == student.StudentId && !a.IsCanceled && !a.IsDenied); if (existingLetter != null) { ViewBag.AllowChange = false; } else { ViewBag.AllowChange = true; } var visaLetter = new VisaLetter(); visaLetter.Student = student; visaLetter.Ceremony = model.Ceremony; visaLetter.MajorName = model.MajorName; visaLetter.RelationshipToStudent = model.RelationshipToStudent; visaLetter.RelativeFirstName = model.RelativeFirstName; visaLetter.RelativeLastName = model.RelativeLastName; visaLetter.RelativeMailingAddress = model.RelativeMailingAddress; visaLetter.RelativeTitle = model.RelativeTitle; visaLetter.StudentFirstName = model.StudentFirstName; visaLetter.StudentLastName = model.StudentLastName; visaLetter.Gender = model.Gender; visaLetter.CollegeCode = model.CollegeCode; if (!string.IsNullOrWhiteSpace(visaLetter.CollegeCode)) { visaLetter.CollegeName = SelectLists.CollegeNames.Single(a => a.Value == visaLetter.CollegeCode).Text; } visaLetter.Degree = model.Degree; visaLetter.HardCopy = model.HardCopy; var termCode = TermService.GetCurrent(); var currentReg = _registrationRepository.Queryable.SingleOrDefault(a => a.Student == student && a.TermCode.Id == termCode.Id); // has this student registered yet? if (currentReg != null) { // display previous registration var participation = currentReg.RegistrationParticipations.FirstOrDefault(a => !a.Cancelled && !a.Registration.Student.SjaBlock && !a.Registration.Student.Blocked); if (participation != null && participation.Ceremony.Colleges.Any(a => a.Id == visaLetter.CollegeCode)) { visaLetter.CeremonyDateTime = participation.Ceremony.DateTime; } } visaLetter.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { //TODO: Try and pull to see if student is registered. If so, set values for which ceremony and which date. Repository.OfType<VisaLetter>().EnsurePersistent(visaLetter); Message = "Request Created"; return this.RedirectToAction("VisaLetterReceipt"); } Message = "Please correct errors and try again."; return View(visaLetter); }
public ActionResult RequestVisaLetter() { // validate student is in our DB, otherwise we need to do a lookup var student = GetCurrentStudent(); // we were just unable to find record if (student == null) return this.RedirectToAction<ErrorController>(a => a.NotFound()); var existingLetter = Repository.OfType<VisaLetter>().Queryable.FirstOrDefault(a => a.Student.StudentId == student.StudentId && !a.IsCanceled && !a.IsDenied); ViewBag.AllowChange = true; var letter = new VisaLetter(); letter.Student = student; if (existingLetter != null) { letter.StudentFirstName = existingLetter.StudentFirstName; letter.StudentLastName = existingLetter.StudentLastName; letter.MajorName = existingLetter.MajorName; letter.CollegeCode = existingLetter.CollegeCode; letter.Gender = existingLetter.Gender; letter.CollegeName = existingLetter.CollegeName; letter.Degree = existingLetter.Degree; letter.HardCopy = existingLetter.HardCopy; letter.Ceremony = existingLetter.Ceremony; ViewBag.AllowChange = false; ViewBag.AllowCeremonyChange = false; } else { letter.StudentFirstName = student.FirstName; letter.StudentLastName = student.LastName; var major = student.Majors.FirstOrDefault(); if (major != null) { letter.MajorName = major.MajorName; letter.CollegeCode = major.College.Id; } } var checkStudent = CheckStudentForVisaLetter(); switch (checkStudent) { case "NotEligible": return this.RedirectToAction<ErrorController>(a => a.NotEligible()); //Blocked case "SJA": return this.RedirectToAction<ErrorController>(a => a.SJA()); case "S": letter.Ceremony = 'S'; ViewBag.AllowCeremonyChange = false; break; case "F": letter.Ceremony = 'F'; ViewBag.AllowCeremonyChange = false; break; case "PreviouslyWalked": return this.RedirectToAction<ErrorController>(a => a.PreviouslyWalked()); case "CeremonyOver": return this.RedirectToAction<ErrorController>(a => a.CeremonyOver()); } return View(letter); }
public void QueueVisaLetterDecision(VisaLetter visaLetter, Ceremony ceremony, HttpRequestBase request, UrlHelper url) { Check.Require(visaLetter != null, "Visa Letter Request Required."); var template = ceremony.Templates.FirstOrDefault(a => a.TemplateType.Name == StaticValues.Template_VisaLetterDecision && a.IsActive); if (template != null) { var subject = template.Subject; var body = _letterGenerator.GenerateVisaLetterRequestDecision(visaLetter, template, request, url); var emailQueue = new EmailQueue(visaLetter.Student, template, subject, body); _emailQueueRepository.EnsurePersistent(emailQueue); } }