CmsData.EmailReplacements.RenderCode C# (CSharp) Method

RenderCode() public method

public RenderCode ( string code, Person p, int orgId = null ) : string
code string
p Person
orgId int
return string
        public string RenderCode(string code, Person p, int? orgId = null)
        {
            if (!code.StartsWith("{"))
                code = $"{{{code}}}";

            PayInfo pi = null;
            if (orgId != null)
                pi = GetPayInfo(orgId.Value, p.PeopleId);

            return DoReplaceCode(code, p, pi, new EmailQueueTo() {OrgId = orgId, PeopleId = p.PeopleId});
        }

Usage Example

Ejemplo n.º 1
0
        public static void RegisterHelpers(CMSDataContext db)
        {
            Handlebars.RegisterHelper("BottomBorder", (writer, context, args) => { writer.Write(CssStyle.BottomBorder); });
            Handlebars.RegisterHelper("AlignTop", (writer, context, args) => { writer.Write(CssStyle.AlignTop); });
            Handlebars.RegisterHelper("AlignRight", (writer, context, args) => { writer.Write(CssStyle.AlignRight); });
            Handlebars.RegisterHelper("DataLabelStyle", (writer, context, args) => { writer.Write(CssStyle.DataLabelStyle); });
            Handlebars.RegisterHelper("LabelStyle", (writer, context, args) => { writer.Write(CssStyle.LabelStyle); });
            Handlebars.RegisterHelper("DataStyle", (writer, context, args) => { writer.Write(CssStyle.DataStyle); });

            Handlebars.RegisterHelper("ServerLink", (writer, context, args) => { writer.Write(db.ServerLink().TrimEnd('/')); });
            Handlebars.RegisterHelper("FmtZip", (writer, context, args) => { writer.Write(args[0].ToString().FmtZip()); });
            Handlebars.RegisterHelper("IfEqual", (writer, options, context, args) =>
            {
                if (IsEqual(args))
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            Handlebars.RegisterHelper("IfNotEqual", (writer, options, context, args) =>
            {
                if (!IsEqual(args))
                {
                    options.Template(writer, (object)context);
                }
                else
                {
                    options.Inverse(writer, (object)context);
                }
            });
            Handlebars.RegisterHelper("GetToken", (writer, context, args) =>
            {
                var s     = args[0].ToString();
                var n     = args[1].ToInt();
                var ntoks = args.Length > 2 ? args[2].ToInt() : 2;
                var sep   = args.Length > 3 ? args[3].ToString() : " ";
                var a     = s.SplitStr(sep, ntoks);
                writer.Write(a[n].trim());
            });

            // Format helper in form of:  {{Fmt value "fmt"}}
            // ex. {{Fmt Total "C"}}
            // fmt is required. Uses standard/custom dotnet format strings
            Handlebars.RegisterHelper("Fmt", (writer, context, args) =>
            {
                var fmt = $"{{0:{args[1]}}}";
                writer.Write(fmt, args[0]);
            });

            // FmtPhone helper in form of:  {{FmtPhone phone# "prefix"}}
            Handlebars.RegisterHelper("FmtPhone", (writer, context, args) => { writer.Write(args[0].ToString().FmtFone($"{args[1]}")); });

            Handlebars.RegisterHelper("ReplaceCode", (writer, context, args) =>
            {
                EmailReplacements r = context.Replacements as EmailReplacements
                                      ?? (context.Replacements = new EmailReplacements(db));
                var code = args[0].ToString();
                var p    = db.LoadPersonById(args[1].ToInt());
                int?oid  = null;
                if (args.Length == 3)
                {
                    oid = args[2].ToInt2();
                }
                writer.Write(r.RenderCode(code, p, oid));
            });
        }
All Usage Examples Of CmsData.EmailReplacements::RenderCode