示例#1
0
        /// <summary>
        /// Replace {{field placeholders}} with smart template
        /// </summary>
        /// <param name="html">Template letter that need to be parsed</param>
        /// <param name="fields">Data that will be include into text</param>
        /// <returns>Sring for sending</returns>
        public string ReplaceFieldsTemplate(string html, YahrtzeitFieldsDto fields, string country = null)
        {
            string smartString = html.Replace("{{", "{").Replace("}}", "}");

            if (smartString.Contains("{AddressBlock}"))
            {
                smartString = FillAddressBlock(smartString, fields, country);
            }

            string resultString = SmartFormat.Smart.Format(smartString, fields);

            return(resultString);
        }
示例#2
0
        private string FillAddressBlock(string smartString, YahrtzeitFieldsDto fields, string country = null)
        {
            StringBuilder addrBlock = new StringBuilder();

            addrBlock.Append(fields.Label);
            if (!string.IsNullOrEmpty(fields.CompanyName))
            {
                addrBlock.Append($"\n{fields.CompanyName}");
            }
            addrBlock.Append($"\n{fields.Address}");
            if (!string.IsNullOrEmpty(fields.Address2))
            {
                addrBlock.Append($"\n{fields.Address2}");
            }
            if (!string.IsNullOrEmpty(fields.City) || !string.IsNullOrEmpty(fields.State) ||
                string.IsNullOrEmpty(fields.Zip))
            {
                addrBlock.Append("\n");
            }
            if (!string.IsNullOrEmpty(fields.City))
            {
                addrBlock.Append($"{fields.City}, ");
            }
            if (!string.IsNullOrEmpty(fields.State))
            {
                addrBlock.Append($"{fields.State} ");
            }
            if (!string.IsNullOrEmpty(fields.Zip))
            {
                addrBlock.Append($"{fields.Zip} ");
            }
            if (!string.IsNullOrEmpty(fields.Country) && !string.IsNullOrEmpty(country) &&
                string.Equals(fields.Country, country, StringComparison.CurrentCultureIgnoreCase))
            {
                addrBlock.Append($"\n{fields.Country} ");
            }
            return(smartString.Replace("{AddressBlock}", addrBlock.ToString()));
        }