Beispiel #1
0
        private static string ReplaceRegistrationUrl(UserConnection userConnection, Guid contactId,
                                                     string confirmRegistrationUrl, Entity template)
        {
            var body       = template.GetTypedColumnValue <string>("Body").Replace("#RegistrationUrl#", confirmRegistrationUrl);
            var macros     = template.GetBytesValue("Macros");
            var macrosList = Json.Deserialize <List <DictionaryEntry> >(Encoding.UTF8.GetString(macros));

            try {
                body = EmailTemplateUtility.ReplaceRecipientMacrosText(body, contactId, macrosList, userConnection);
            } catch { }
            return(body);
        }
        public virtual string ProcessEmailBody(string body, Guid contactId, byte[] macrosBytes)
        {
            var url = GetVisaLink();

            body = string.Format(body, url);

            var visaEntitySchemaQuery = GetVisaTemplateEntitySchemaQuery();
            var visaEntityCollection  = visaEntitySchemaQuery.GetEntityCollection(UserConnection);

            if (visaEntityCollection.Count == 0)
            {
                return(body);
            }
            var visaEntity   = visaEntityCollection[0];
            var addedColumns = (List <EntitySchemaQueryColumn>)AddedTemplateColumns;

            StringBuilder sbBody = new StringBuilder(body);

            foreach (EntitySchemaQueryColumn esqColumn in addedColumns)
            {
                var value       = visaEntity.GetColumnValue(esqColumn.Name);
                var stringValue = value is DateTime ? ((DateTime)value).ToShortDateString() : value.ToString();
                var caption     = esqColumn.Caption.ToString();
                if (String.IsNullOrEmpty(stringValue))
                {
                    var   reqexp = string.Format("#DeleteIfEmpty#([^#]*?)\\[#{0}#\\]([^#]*?)#\\/DeleteIfEmpty#", caption);
                    Regex r      = new Regex(reqexp);
                    foreach (Match match in r.Matches(body))
                    {
                        sbBody.Replace(match.Value, string.Empty);
                    }
                }
                sbBody.Replace(string.Format("[#{0}#]", esqColumn.Caption.ToString()), stringValue);
            }
            sbBody.Replace("#DeleteIfEmpty#", string.Empty);
            sbBody.Replace("#/DeleteIfEmpty#", string.Empty);
            sbBody.Insert(0, "<div style=\"font-family: 'Verdana';\">");
            sbBody.Append("</div>");
            body = sbBody.ToString();
            var macrosList = Json.Deserialize <List <DictionaryEntry> >(System.Text.Encoding.UTF8.GetString(macrosBytes));

            body = EmailTemplateUtility.ReplaceRecipientMacrosText(body, contactId, macrosList, UserConnection);
            return(body);
        }