コード例 #1
0
        /// <summary>
        /// Sends an email for 1*1 bookings or extrabookings
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="booking"></param>
        /// <param name="bookingExtraSelection"></param>
        public StandardEmailTemplate(string toEmailAddress, int EmailTemplateID, Customer customer, Booking booking = null, BookingExtraSelection bookingExtraSelection = null)
        {

            EmailTemplate theTemplate;
            EmailTemplate Header;
            EmailTemplate Footer;

            using (PortugalVillasContext db = new PortugalVillasContext())
            {
                theTemplate = db.EmailTemplates.Find(EmailTemplateID);
                Header = db.EmailTemplates.Find(1);
                Footer = db.EmailTemplates.Find(2);
            }
            theAsposeMessage = new MailMessage();
            Property property = null;
            BookingExtra bookingExtra = null;

            EmailOutType theMainBody = new EmailOutType();

            //map all passed in object fields
            bool bookingToggle = false;
            bool bookingExtraToggle = false;
            bool combinedServicesToggle = false;


            //gets necessary

            //assign body
            if (booking == null)
            {
                bookingExtraToggle = true;
                bookingExtra = BookingExtra.GetBookingExtraByID(bookingExtraSelection.BookingExtraID);
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingExtraSelectionConfirm);
            }
            else if (booking != null && bookingExtraSelection == null)
            {
                bookingToggle = true;
                long propertyID = (long)booking.PropertyID;
                property = Property.GetPropertyByID(propertyID);
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingConfirm);//
            }
            else if (booking != null && bookingExtraSelection != null)
            {
                long propertyID = (long)booking.PropertyID;
                property = Property.GetPropertyByID(propertyID);
                bookingExtra = BookingExtra.GetBookingExtraByID(bookingExtraSelection.BookingExtraID);
                combinedServicesToggle = true;
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingAndBookingExtraSelectionConfirm);
            }







            //customer
            var customerFullName = customer.FirstName + " " + customer.LastName;

            //bookings and extras

            var prcRef = booking != null ? property.LegacyReference : bookingExtra.LegacyReference;

            string bookingPropertyOrSelectionName = booking != null ? property.PropertyName : bookingExtra.BookingExtraName;
            string bookingStartDate = booking != null ? Convert.ToDateTime(booking.StartDate.ToString()).ToString("dd/MM/yyyy") : Convert.ToDateTime(bookingExtraSelection.ExtraRentalDate.ToString()).ToString("dd/MM/yyyy");
            string bookingEndDate = booking != null ? Convert.ToDateTime(booking.EndDate.ToString()).ToString("dd/MM/yyyy") : new DateTime(1901, 01, 01).ToString("dd/MM/yyyy");
            string numberOfNights = booking != null ? booking.NumberOfNights.ToString() : "0";


            theAsposeMessage.To = customer.EmailAddress;
            theAsposeMessage.From = "*****@*****.**";

            theSMTPClient.Host = "smtp.gmail.com";
            theSMTPClient.Username = LoginEmailAddress;
            theSMTPClient.Password = EmailPassword;
            theSMTPClient.Port = 587;
            theSMTPClient.EnableSsl = true;
            theSMTPClient.SecurityMode = SmtpSslSecurityMode.Explicit;


            //set some email body   
            //set the body
            //subject
            //           
            theAsposeMessage.Subject = theTemplate.EmailSubject;
            theAsposeMessage.HtmlBody = "";

            //get correct email according to emailEnumID


            var temp = "";
            //string merges
            var fullName = customer != null ? customerFullName : "";
            var legacyRef = property != null ? property.LegacyReference : bookingExtra.LegacyReference;
            var bookStart = bookingStartDate != null ? bookingStartDate : "";
            var bookEnd = bookingEndDate != null ? bookingEndDate : "";
            var NoNights = numberOfNights != null ? numberOfNights : "";
            var reference = booking != null ? booking.BookingPRCReference : bookingExtraSelection.BookingExtraPRCReference;
            var bID = booking != null ? booking.BookingID.ToString() : "";
            var besID = bookingExtraSelection != null ? bookingExtraSelection.BookingExtraSelectionID.ToString() : "";
            
            var finalRentalPayment = booking != null ? booking.BookingPrice.ToString() : "";
            var finalRentalPaymentDate = "";
                if(booking != null)
                {
                   finalRentalPaymentDate =  booking.FinalRentalPaymentDueDate != null ? ((DateTime)booking.FinalRentalPaymentDueDate).ToString("dd/MM/yyyy") : "";
                }

            var rentalDeposit = booking != null ? booking.BreakageDeposit.ToString() : "";

            temp = String.Format(theTemplate.EmailTemplateBodyHTML, fullName, legacyRef, bookStart, bookEnd, NoNights, reference, finalRentalPaymentDate, bID, besID, finalRentalPayment, rentalDeposit);

            //booking request optional
            //if (bookingToggle == true && EmailTemplateID == 17)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, property.LegacyReference, bookingStartDate, bookingEndDate, numberOfNights, bookingExtraSelection.BookingExtraSelectionID);
            //}

            ////booking request forms standard
            //else if (bookingToggle == true // && EmailTemplateID == 3 || EmailTemplateID == 4 || EmailTemplateID == 5 || EmailTemplateID == 6
            //    )
            //{


            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, property.LegacyReference, booking.BookingPRCReference, ((DateTime)booking.FinalRentalPaymentDueDate).ToString("dd/MM/yyyy"));


            //}


            //else if (bookingExtraToggle == true)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, prcRef, bookingExtraSelection.BookingExtraSelectionID);

            //}
            //else if (combinedServicesToggle == true)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, booking.BookingID);

            //}






            //set the body
            var completeEmail = Header.EmailTemplateBodyHTML + temp + Footer.EmailTemplateBodyHTML;

            theAsposeMessage.HtmlBody = completeEmail;


        }
コード例 #2
0
        /// <summary>
        /// Sends an email for 1*1 bookings or extrabookings
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="booking"></param>
        /// <param name="bookingExtraSelection"></param>
        public StandardEmailTemplate(string toEmailAddress, int EmailTemplateID, Customer customer, Booking booking = null, BookingExtraSelection bookingExtraSelection = null)
        {
            EmailTemplate theTemplate;
            EmailTemplate Header;
            EmailTemplate Footer;

            using (PortugalVillasContext db = new PortugalVillasContext())
            {
                theTemplate = db.EmailTemplates.Find(EmailTemplateID);
                Header      = db.EmailTemplates.Find(1);
                Footer      = db.EmailTemplates.Find(2);
            }
            theAsposeMessage = new MailMessage();
            Property     property     = null;
            BookingExtra bookingExtra = null;

            EmailOutType theMainBody = new EmailOutType();

            //map all passed in object fields
            bool bookingToggle          = false;
            bool bookingExtraToggle     = false;
            bool combinedServicesToggle = false;


            //gets necessary

            //assign body
            if (booking == null)
            {
                bookingExtraToggle = true;
                bookingExtra       = BookingExtra.GetBookingExtraByID(bookingExtraSelection.BookingExtraID);
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingExtraSelectionConfirm);
            }
            else if (booking != null && bookingExtraSelection == null)
            {
                bookingToggle = true;
                long propertyID = (long)booking.PropertyID;
                property = Property.GetPropertyByID(propertyID);
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingConfirm);//
            }
            else if (booking != null && bookingExtraSelection != null)
            {
                long propertyID = (long)booking.PropertyID;
                property               = Property.GetPropertyByID(propertyID);
                bookingExtra           = BookingExtra.GetBookingExtraByID(bookingExtraSelection.BookingExtraID);
                combinedServicesToggle = true;
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingAndBookingExtraSelectionConfirm);
            }



            //customer
            var customerFullName = customer.FirstName + " " + customer.LastName;

            //bookings and extras

            var prcRef = booking != null ? property.LegacyReference : bookingExtra.LegacyReference;

            string bookingPropertyOrSelectionName = booking != null ? property.PropertyName : bookingExtra.BookingExtraName;
            string bookingStartDate = booking != null?Convert.ToDateTime(booking.StartDate.ToString()).ToString("dd/MM/yyyy") : Convert.ToDateTime(bookingExtraSelection.ExtraRentalDate.ToString()).ToString("dd/MM/yyyy");

            string bookingEndDate = booking != null?Convert.ToDateTime(booking.EndDate.ToString()).ToString("dd/MM/yyyy") : new DateTime(1901, 01, 01).ToString("dd/MM/yyyy");

            string numberOfNights = booking != null?booking.NumberOfNights.ToString() : "0";


            theAsposeMessage.To   = customer.EmailAddress;
            theAsposeMessage.From = "*****@*****.**";

            theSMTPClient.Host         = "smtp.gmail.com";
            theSMTPClient.Username     = LoginEmailAddress;
            theSMTPClient.Password     = EmailPassword;
            theSMTPClient.Port         = 587;
            theSMTPClient.EnableSsl    = true;
            theSMTPClient.SecurityMode = SmtpSslSecurityMode.Explicit;


            //set some email body
            //set the body
            //subject
            //
            theAsposeMessage.Subject  = theTemplate.EmailSubject;
            theAsposeMessage.HtmlBody = "";

            //get correct email according to emailEnumID


            var temp = "";
            //string merges
            var fullName  = customer != null ? customerFullName : "";
            var legacyRef = property != null ? property.LegacyReference : bookingExtra.LegacyReference;
            var bookStart = bookingStartDate != null ? bookingStartDate : "";
            var bookEnd   = bookingEndDate != null ? bookingEndDate : "";
            var NoNights  = numberOfNights != null ? numberOfNights : "";
            var reference = booking != null ? booking.BookingPRCReference : bookingExtraSelection.BookingExtraPRCReference;
            var bID       = booking != null?booking.BookingID.ToString() : "";

            var besID = bookingExtraSelection != null?bookingExtraSelection.BookingExtraSelectionID.ToString() : "";

            var finalRentalPayment = booking != null?booking.BookingPrice.ToString() : "";

            var finalRentalPaymentDate = "";

            if (booking != null)
            {
                finalRentalPaymentDate = booking.FinalRentalPaymentDueDate != null ? ((DateTime)booking.FinalRentalPaymentDueDate).ToString("dd/MM/yyyy") : "";
            }

            var rentalDeposit = booking != null?booking.BreakageDeposit.ToString() : "";

            temp = String.Format(theTemplate.EmailTemplateBodyHTML, fullName, legacyRef, bookStart, bookEnd, NoNights, reference, finalRentalPaymentDate, bID, besID, finalRentalPayment, rentalDeposit);

            //booking request optional
            //if (bookingToggle == true && EmailTemplateID == 17)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, property.LegacyReference, bookingStartDate, bookingEndDate, numberOfNights, bookingExtraSelection.BookingExtraSelectionID);
            //}

            ////booking request forms standard
            //else if (bookingToggle == true // && EmailTemplateID == 3 || EmailTemplateID == 4 || EmailTemplateID == 5 || EmailTemplateID == 6
            //    )
            //{


            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, property.LegacyReference, booking.BookingPRCReference, ((DateTime)booking.FinalRentalPaymentDueDate).ToString("dd/MM/yyyy"));


            //}


            //else if (bookingExtraToggle == true)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, prcRef, bookingExtraSelection.BookingExtraSelectionID);

            //}
            //else if (combinedServicesToggle == true)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, booking.BookingID);

            //}



            //set the body
            var completeEmail = Header.EmailTemplateBodyHTML + temp + Footer.EmailTemplateBodyHTML;

            theAsposeMessage.HtmlBody = completeEmail;
        }