예제 #1
0
        public string GenerateEmailBody(string TemplateName, Object model = null, OutgoingEmailLogModel outgoingEmailLogModel = null)
        {
            var EmailBody              = string.Empty;
            var HashCriteria           = new Hashtable();
            var HashCriteriaTemplate   = new Hashtable();
            var actualCriteria         = string.Empty;
            var actualCriteriaTemplate = string.Empty;
            var serialization          = new Serialization();
            var emailNotificationBA    = new EmailNotifications();

            HashCriteriaTemplate.Add("TemplateCode", TemplateName);
            actualCriteriaTemplate = serialization.SerializeBinary((object)HashCriteriaTemplate);
            var result = Convert.ToString(emailNotificationBA.GetHtmlForTemplate(actualCriteriaTemplate));

            EmailBody = Convert.ToString(serialization.DeSerializeBinary(Convert.ToString(result)));
            EmailBody = EmailBody.Replace("##Year##", Convert.ToString(DateTime.Now.ToString("yyyy")));
            if (!string.IsNullOrEmpty(outgoingEmailLogModel.DomainName))
            {
                EmailBody = EmailBody.Replace("##Domain##", outgoingEmailLogModel.DomainName);
            }

            switch (TemplateName)
            {
            case "ForgotPassword":
                var forgotPassword = (ForgotPassword)model;
                var newGuid        = Guid.NewGuid();
                outgoingEmailLogModel.Token = newGuid.ToString();
                HashCriteria.Add("Email", forgotPassword.Email);
                actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                var resultEmail = emailNotificationBA.GetUserNameFromEmailAddress(actualCriteria);      // Get username from email address to display in template
                var UserName    = Convert.ToString(serialization.DeSerializeBinary(Convert.ToString(resultEmail)));
                if (!string.IsNullOrEmpty(forgotPassword.Email))
                {
                    EmailBody = EmailBody.Replace("##UserName##", UserName);
                }
                if (!string.IsNullOrEmpty(outgoingEmailLogModel.Token))
                {
                    EmailBody = EmailBody.Replace("##Token##", outgoingEmailLogModel.Token);
                }
                break;

            case "Registration":
                var Registration = (UserProfileModel)model;
                if (!string.IsNullOrEmpty(Registration.Name))
                {
                    EmailBody = EmailBody.Replace("##UserName##", Registration.Name);
                    EmailBody = EmailBody.Replace("##DiscourseURL##", Convert.ToString(ConfigurationManager.AppSettings["DiscourseUrl"]));
                }

                break;

            case "ContactBroker":
                var contactBroker = outgoingEmailLogModel;
                if (!string.IsNullOrEmpty(contactBroker.DealName))
                {
                    EmailBody = EmailBody.Replace("##DealName##", contactBroker.DealName);
                }
                if (!string.IsNullOrEmpty(contactBroker.ReceiverName))
                {
                    EmailBody = EmailBody.Replace("##BrokerName##", contactBroker.ReceiverName);
                }
                if (!string.IsNullOrEmpty(contactBroker.MessageBody))
                {
                    EmailBody = EmailBody.Replace("##Message##", contactBroker.MessageBody);
                }
                if (!string.IsNullOrEmpty(contactBroker.MessageSender))
                {
                    EmailBody = EmailBody.Replace("##MessageSender##", contactBroker.MessageSender);
                }
                break;

            case "ScheduleConsultation":
                var scheduleConsultation = outgoingEmailLogModel;
                if (!string.IsNullOrEmpty(scheduleConsultation.DealName))
                {
                    EmailBody = EmailBody.Replace("##DealName##", scheduleConsultation.DealName);
                }
                if (!string.IsNullOrEmpty(scheduleConsultation.ReceiverName))
                {
                    EmailBody = EmailBody.Replace("##BrokerName##", scheduleConsultation.ReceiverName);
                }
                if (!string.IsNullOrEmpty(scheduleConsultation.MessageBody))
                {
                    EmailBody = EmailBody.Replace("##Message##", scheduleConsultation.MessageBody);
                }
                if (!string.IsNullOrEmpty(scheduleConsultation.MessageSender))
                {
                    EmailBody = EmailBody.Replace("##MessageSender##", scheduleConsultation.MessageSender);
                }
                if (!string.IsNullOrEmpty(scheduleConsultation.EmailTo))
                {
                    EmailBody = EmailBody.Replace("##Email##", scheduleConsultation.EmailFrom);
                }
                if (!string.IsNullOrEmpty(scheduleConsultation.PhoneNumber))
                {
                    EmailBody = EmailBody.Replace("##PhoneNumber##", scheduleConsultation.PhoneNumber);
                }
                else
                {
                    EmailBody = EmailBody.Replace("##PhoneNumber##", "Not Provided");
                }
                break;

            case "MessageCenter":
                var MessageCenter = outgoingEmailLogModel;
                if (!string.IsNullOrEmpty(MessageCenter.DealName))
                {
                    EmailBody = EmailBody.Replace("##DealName##", MessageCenter.DealName);
                }
                if (!string.IsNullOrEmpty(MessageCenter.ReceiverName))
                {
                    EmailBody = EmailBody.Replace("##ReceiverName##", MessageCenter.ReceiverName);
                }
                if (!string.IsNullOrEmpty(MessageCenter.MessageBody))
                {
                    EmailBody = EmailBody.Replace("##Message##", MessageCenter.MessageBody);
                }
                if (!string.IsNullOrEmpty(MessageCenter.MessageSender))
                {
                    EmailBody = EmailBody.Replace("##MessageSender##", MessageCenter.MessageSender);
                }
                break;

            case "ContactBrokerUnlikeListing":
                var contactBrokerUnlikeListing = outgoingEmailLogModel;
                if (!string.IsNullOrEmpty(contactBrokerUnlikeListing.ReceiverName))
                {
                    EmailBody = EmailBody.Replace("##BrokerName##", contactBrokerUnlikeListing.ReceiverName);
                }
                if (!string.IsNullOrEmpty(contactBrokerUnlikeListing.MessageBody))
                {
                    EmailBody = EmailBody.Replace("##Message##", contactBrokerUnlikeListing.MessageBody);
                }
                if (!string.IsNullOrEmpty(contactBrokerUnlikeListing.MessageSender))
                {
                    EmailBody = EmailBody.Replace("##MessageSender##", contactBrokerUnlikeListing.MessageSender);
                }
                break;
            }
            return(EmailBody);
        }