public BookingInfo(BookingDispatching dispatch, Association association, AirportMeetingPoint meetingPoint) { _dispatch = dispatch; _booking = dispatch.Booking; _association = association; _airportMeetingPoint = meetingPoint; }
public static Document Generate(BookingDispatching dispatch, Association association, AirportMeetingPoint meetingPoint) { BookingInfo bookingInfo = new BookingInfo(dispatch, association, meetingPoint); Document document = new Document(); document.Info.Title = "Confirmation Voucher"; document.Info.Subject = dispatch.Booking.ReferenceId; document.Info.Author = bookingInfo.AssociationName; DefineStyles(document); Section section = document.AddSection(); AddLogo(document, bookingInfo); AddTripSummary(document, bookingInfo); AddMeetingPoint(document, bookingInfo); AddPassengers(document, bookingInfo); section.AddParagraph(); AddPayment(document, bookingInfo); AddBookedByInfo(document, bookingInfo); return document; }
public bool Equals(BookingDispatching other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; if (other.BookingId == 0 && BookingId == 0) return false; else return other.BookingId == BookingId; }
public string SendVoucher(int bookingId, IEnumerable<string> emails) { try { using (var db = new LomsContext()) { string[] bookingChildren3 = new[] { "Creator", "City", "City.Country", "City.State", "City.State.Country", "PickUpEndpoint", "PickUpEndpoint.Airport", "PickUpEndpoint.Airline", "PickUpEndpoint.Suburb", "PickUpEndpoint.Suburb.Country", "PickUpEndpoint.Suburb.State", "PickUpEndpoint.Suburb.State.Country", "DropOffEndpoint", "DropOffEndpoint.Airport", "DropOffEndpoint.Airline", "DropOffEndpoint.Suburb", "DropOffEndpoint.Suburb.Country", "DropOffEndpoint.Suburb.State", "DropOffEndpoint.Suburb.State.Country", "Stops", "VehicleType", //"FareInfo", "FareInfo.Currency", "FareInfo.Items", "PrimaryPassenger", "PassengerInfo","PassengerInfo.Adults","PassengerInfo.Childs","PassengerInfo.Infants", "ProvisionInfo", "TransactionCreditCards", "TransactionCreditCards.Address", "TransactionCreditCards.Info" //"PaymentInfo.CreditCard", "PaymentInfo.CreditCard.Info", //"PaymentInfo.BillingAccount", "PaymentInfo.BillingAccount.ChargeBack", "PaymentInfo.BillingAccount.ChargeBack.Country", //"PaymentInfo.Items" }; string[] bookingPaymentInfoChildren = new[] { "CreditCard", "CreditCard.Info", "BillingAccount", "BillingAccount.ChargeBack", "BillingAccount.ChargeBack.Country", "Items" }; var booking = db.Bookings.IncludeAll(bookingChildren3).FirstOrDefault(b => b.Id == bookingId); booking.PaymentInfo = db.BookingPayments.IncludeAll(bookingPaymentInfoChildren).FirstOrDefault(b => b.BookingId == bookingId); var primaryPassenger = booking.PrimaryPassenger != null ? booking.PrimaryPassenger : booking.Creator; booking.ChargeInfo = db.BookingChargeInfoes.Include("Items").SingleOrDefault(b => b.BookingId == bookingId); booking.TransactionBillingAccount = db.BookingTransactionBillingAccounts.Include("ChargeBack").SingleOrDefault(b => b.BillingAccountId == bookingId); booking.TransactionCreditCards.ForEach(i => { i.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(i.Info.Number); i.Info = null; i.AcceptChanges(); }); BookingDispatching dispatch = db.BookingDispatchings.FirstOrDefault(b => b.BookingId == bookingId); if (dispatch == null) dispatch = new BookingDispatching(); dispatch.Booking = booking; if (booking.Creator.IsTravelAgency) { booking.Creator.TravelAgencyRole = db.AssociationUserTravelAgencyRoles.IncludeAll("TravelAgency").SingleOrDefault(r => r.UserId == booking.Creator.Id && r.StatusId == (int)TravelAgencyStatus.Accepted); if (booking.Creator.TravelAgencyRole != null) { booking.Creator.TravelAgencyName = booking.Creator.TravelAgencyRole.TravelAgency.Name; booking.Creator.MarkAsUnchanged(); } } var emailProvider = db.AssociationEmails.FirstOrDefault(e => e.AssociationId == CurrentAssociationId); if (emailProvider != null) { var association = db.Associations.FirstOrDefault(a => a.Id == CurrentAssociationId); var uri = HttpContext.Current.Request.Url; string baseUrl = String.Format("{0}://{1}:{2}", uri.Scheme, uri.Host ?? "80", uri.Port); string contactUsLink = Path.Combine(baseUrl + "/#Contact"); EmailTemplate emailTemplate = new EmailTemplate("ConfirmationVoucher"); emailTemplate["UserName"] = primaryPassenger.FullName.ToUpper(); emailTemplate["AssociationName"] = association.Name.ToUpper(); emailTemplate["BookingId"] = booking.ReferenceId; var avBody = AlternateView.CreateAlternateViewFromString(emailTemplate.Html, null, MediaTypeNames.Text.Html); string email = null; bool first = true; foreach (string item in emails) { if (!first) email += ","; email += item; first = false; } ////generate voucher //var document = BookingVoucher.Generate(booking); ////MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); //PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); //renderer.Document = document; //renderer.RenderDocument(); //MemoryStream stream = new MemoryStream(); //renderer.PdfDocument.Save(stream, false); CommonBookingService commonService = new CommonBookingService(); AirportMeetingPoint meetingPoint = commonService.GetMeetingPoint(db, booking); MemoryStream stream = commonService.GeneratePDFVoucher(dispatch, association, meetingPoint); Attachment attach = new Attachment(stream, booking.ReferenceId + ".pdf", "application/pdf"); emailProvider.SendMail(email, "Itinerary for " + primaryPassenger.LastName, emailTemplate.Txt, attach, avBody, true); } } } catch (Exception ex) { return ex.ToString(); } return null; }
public MemoryStream GeneratePDFVoucher(BookingDispatching dispatch, Association association, AirportMeetingPoint meetingPoint) { var document = BookingVoucher.Generate(dispatch, association, meetingPoint); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = document; renderer.RenderDocument(); MemoryStream pdfStream = new MemoryStream(); renderer.PdfDocument.Save(pdfStream, false); return pdfStream; }
/// <summary> /// Get the PDF in bytes for vouchers, this PDF byte can be used to attached in Email or send to client directly for downloading /// </summary> /// <param name="bookingId">BookingId</param> /// <param name="associationId">AssociationId</param> /// <returns></returns> public byte[] GetVoucherBytes(int bookingId, int associationId) { byte[] pdfBytes = null; try { using (var db = new LomsContext()) { string[] bookingChildren3 = new[] { "Creator", "City", "City.Country", "City.State", "City.State.Country", "PickUpEndpoint", "PickUpEndpoint.Airport", "PickUpEndpoint.Airline", "PickUpEndpoint.Suburb", "PickUpEndpoint.Suburb.Country", "PickUpEndpoint.Suburb.State", "PickUpEndpoint.Suburb.State.Country", "DropOffEndpoint", "DropOffEndpoint.Airport", "DropOffEndpoint.Airline", "DropOffEndpoint.Suburb", "DropOffEndpoint.Suburb.Country", "DropOffEndpoint.Suburb.State", "DropOffEndpoint.Suburb.State.Country", "Stops", "VehicleType", "PrimaryPassenger", "PassengerInfo","PassengerInfo.Adults","PassengerInfo.Childs","PassengerInfo.Infants", "ProvisionInfo", "TransactionCreditCards", "TransactionCreditCards.Address", "TransactionCreditCards.Info" }; BookingDispatching dispatch = db.BookingDispatchings.FirstOrDefault(b => b.BookingId == bookingId); if (dispatch == null) dispatch = new BookingDispatching(); Booking booking = db.Bookings.IncludeAll(bookingChildren3).FirstOrDefault(b => b.Id == bookingId); Association association = db.Associations.FirstOrDefault(a => a.Id == associationId); dispatch.Booking = booking; string[] bookingPaymentInfoChildren = new[] { "CreditCard", "CreditCard.Info", "BillingAccount", "BillingAccount.ChargeBack", "BillingAccount.ChargeBack.Country", "Items" }; dispatch.Booking.PaymentInfo = db.BookingPayments.IncludeAll(bookingPaymentInfoChildren).FirstOrDefault(b => b.BookingId == bookingId); booking.ChargeInfo = db.BookingChargeInfoes.Include("Items").SingleOrDefault(b => b.BookingId == bookingId); booking.TransactionBillingAccount = db.BookingTransactionBillingAccounts.Include("ChargeBack").SingleOrDefault(b => b.BillingAccountId == bookingId); booking.TransactionCreditCards.ForEach(i => { i.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(i.Info.Number); i.Info = null; i.AcceptChanges(); }); if (booking.Creator.IsTravelAgency) { booking.Creator.TravelAgencyRole = db.AssociationUserTravelAgencyRoles.IncludeAll("TravelAgency").SingleOrDefault(r => r.UserId == booking.Creator.Id && r.StatusId == (int)TravelAgencyStatus.Accepted); if (booking.Creator.TravelAgencyRole != null) { booking.Creator.TravelAgencyName = booking.Creator.TravelAgencyRole.TravelAgency.Name; booking.Creator.MarkAsUnchanged(); } } //meeting point AirportMeetingPoint meetingPoint = GetMeetingPoint(db, booking); MemoryStream stream = GeneratePDFVoucher(dispatch, association, meetingPoint); pdfBytes = stream.ToArray(); } } catch (Exception ex) { pdfBytes = null; Debug.WriteLine("Error occured while getting pdf bytes: " + ex.Message); //todo log the message throw new Exception("Error while generating PDF", ex); } return pdfBytes; }