CmsData.EmailReplacements.DoReplaceCode C# (CSharp) Метод

DoReplaceCode() приватный Метод

private DoReplaceCode ( string code, Person p, PayInfo pi = null, CmsData.EmailQueueTo emailqueueto = null ) : string
code string
p Person
pi PayInfo
emailqueueto CmsData.EmailQueueTo
Результат string
        private string DoReplaceCode(string code, Person p, PayInfo pi = null, EmailQueueTo emailqueueto = null)
        {
            if (code.StartsWith("<style"))
                return code;
            switch (code.ToLower())
            {
                case "{address}":
                    return p.PrimaryAddress;

                case "{address2}":
                    if (p.PrimaryAddress2.HasValue())
                        return "<br>" + p.PrimaryAddress2;
                    return "";

                case "{amtdue}":
                    if (pi != null)
                        return pi.AmountDue.ToString2("c");
                    break;

                case "{amtpaid}":
                    if (pi != null)
                        return pi.AmountPaid.ToString2("c");
                    break;

                case "{amount}":
                    if (pi != null)
                        return pi.Amount.ToString2("c");
                    break;

                case "{barcode}":
                    return $"<img src='{db.ServerLink("/Track/Barcode/" + p.PeopleId)}' />";

                case "{birthdate}":
                    return Util.FormatBirthday(p.BirthYear, p.BirthMonth, p.BirthDay, "not available");

                case "{campus}":
                    return p.CampusId != null ? p.Campu.Description : $"No {Util2.CampusLabel} Specified";

                case "{cellphone}":
                    return p.CellPhone.HasValue() ? p.CellPhone.FmtFone() : "no cellphone on record";

                case "{city}":
                    return p.PrimaryCity;

                case "{csz}":
                    return Util.FormatCSZ(p.PrimaryCity, p.PrimaryState, p.PrimaryZip);

                case "{country}":
                    return p.PrimaryCountry;

                case "{createaccount}":
                    if (emailqueueto != null)
                        return CreateUserTag(emailqueueto);
                    break;

                case "{church}":
                    return db.Setting("NameOfChurch", "No NameOfChurch in Settings");

                case "{churchphone}":
                    return db.Setting("ChurchPhone", "No ChurchPhone in Settings");

                case "{cmshost}":
                    return db.ServerLink();

                case "{dob}":
                    return p.DOB;

                case "{estatement}":
                    if (p.ElectronicStatement == true)
                        return "Online Electronic Statement Only";
                    else
                        return "Printed Statement in Addition to Online Option";

                case "{emailhref}":
                    if (emailqueueto != null)
                        return db.ServerLink("/EmailView/" + emailqueueto.Id);
                    break;

                case "{first}":
                    return p.PreferredName.Contains("?") || p.PreferredName.Contains("unknown", true) ? "" : p.PreferredName;

                case "{fromemail}":
                    return from.Address;

                case "{homephone}":
                    return p.HomePhone.HasValue() ? p.HomePhone.FmtFone() : "no homephone on record";

                case "{last}":
                    return p.LastName;

                case "{name}":
                    return p.Name.Contains("?") || p.Name.Contains("unknown", true) ? "" : p.Name;

                case "{nextmeetingtime}":
                    if (emailqueueto != null)
                        return NextMeetingDate(emailqueueto.OrgId, emailqueueto.PeopleId) ?? code;
                    break;
                case "{nextmeetingtime0}":
                    if (emailqueueto != null)
                        return NextMeetingDate0(emailqueueto.OrgId) ?? code;
                    break;

                case "{occupation}":
                    return p.OccupationOther;

                case "{orgname}":
                case "{org}":
                    return GetOrgInfo(emailqueueto?.OrgId).Name;

                case "{orgmembercount}":
                    return GetOrgInfo(emailqueueto?.OrgId).Count;

                case "{paylink}":
                    if (pi != null && pi.PayLink.HasValue())
                        return $"<a href=\"{pi.PayLink}\">Click this link to make a payment and view your balance.</a>";
                    break;

                case "{peopleid}":
                    return p.PeopleId.ToString();

                case "{receivesms}":
                    if (p.ReceiveSMS == true)
                        return "Yes";
                    else
                        return "No";

                case "{salutation}":
                    if (emailqueueto != null)
                        return db.GoerSupporters.Where(ee => ee.Id == emailqueueto.GoerSupportId).Select(ee => ee.Salutation).SingleOrDefault();
                    break;

                case "{state}":
                    return p.PrimaryState;

                case "{statementtype}":
                    var stmtcode = p.ContributionOptionsId;
                    switch (stmtcode)
                    {
                        case CmsData.Codes.StatementOptionCode.Individual:
                            return "Individual";

                        case CmsData.Codes.StatementOptionCode.Joint:
                            return "Joint";

                        case CmsData.Codes.StatementOptionCode.None:
                        default:
                            return "None";
                    }

                case "{email}":
                case "{toemail}":
                    if (ListAddresses.Count > 0)
                        return ListAddresses[0].Address;
                    break;

                case "{today}":
                    return DateTime.Today.ToShortDateString();

                case "{title}":
                    if (p.TitleCode.HasValue())
                        return p.TitleCode;
                    return p.ComputeTitle();

                case "{track}":
                    if (emailqueueto != null)
                        return emailqueueto.Guid.HasValue ?
                            $"<img src=\"{db.ServerLink("/Track/Key/" + emailqueueto.Guid.Value.GuidToQuerystring())}\" />"
                            : "";
                    break;

                case "{unsubscribe}":
                    if (emailqueueto != null)
                        return UnSubscribeLink(emailqueueto);
                    break;

                default:
                    if (emailqueueto == null)
                        emailqueueto = new EmailQueueTo()
                        {
                            PeopleId = p.PeopleId,
                            OrgId = db.CurrentOrgId0
                        };

                    if (code.StartsWith("{addsmallgroup:", StringComparison.OrdinalIgnoreCase))
                        return AddSmallGroup(code, emailqueueto);

                    if (code.StartsWith("{extra", StringComparison.OrdinalIgnoreCase))
                        return ExtraValue(code, emailqueueto);

                    if (registerLinkRe.IsMatch(code))
                        return RegisterLink(code, emailqueueto);

                    if (registerHrefRe.IsMatch(code))
                        return RegisterLinkHref(code, emailqueueto);

                    if (registerTagRe.IsMatch(code))
                        return RegisterTag(code, emailqueueto);

                    if (rsvpLinkRe.IsMatch(code))
                        return RsvpLink(code, emailqueueto);

                    if (sendLinkRe.IsMatch(code))
                        return SendLink(code, emailqueueto);

                    if (code.StartsWith("{orgextra:", StringComparison.OrdinalIgnoreCase))
                        return OrgExtra(code, emailqueueto);

                    if (code.StartsWith("{orgmember:", StringComparison.OrdinalIgnoreCase))
                        return OrgMember(code, emailqueueto);

                    if (code.StartsWith("{orgbarcode"))
                        return OrgBarcode(code, emailqueueto);

                    if (code.StartsWith("{smallgroup:", StringComparison.OrdinalIgnoreCase))
                        return SmallGroup(code, emailqueueto);
                    if (code.StartsWith("{subgroup:", StringComparison.OrdinalIgnoreCase))
                        return SmallGroup(code, emailqueueto);

                    if (regTextRe.IsMatch(code))
                        return RegText(code, emailqueueto);

                    if (code.StartsWith("{smallgroups", StringComparison.OrdinalIgnoreCase))
                        return SmallGroups(code, emailqueueto);
                    if (code.StartsWith("{subgroups", StringComparison.OrdinalIgnoreCase))
                        return SmallGroups(code, emailqueueto);

                    if (code.StartsWith("{pledge", StringComparison.OrdinalIgnoreCase))
                        return Pledge(code, emailqueueto);

                    if (supportLinkRe.IsMatch(code))
                        return SupportLink(code, emailqueueto);

                    if (masterLinkRe.IsMatch(code))
                        return MasterLink(code, emailqueueto);

                    if (volReqLinkRe.IsMatch(code))
                        return VolReqLink(code, emailqueueto);

                    if (volSubLinkRe.IsMatch(code))
                        return VolSubLink(code, emailqueueto);

                    if (voteLinkRe.IsMatch(code))
                        return VoteLink(code, emailqueueto);

                    break;
            }

            return code;
        }