Пример #1
0
        public static string LookupUpEmailSourceCode(string sourceCode)
        {
            var sourceType = sourceCode[0];
            var subType    = sourceCode[1];
            var hyphenPos  = sourceCode.IndexOf('-');
            var stateCode  = Empty;

            if (hyphenPos <= 0 || hyphenPos > 2 || sourceCode.Length < hyphenPos + 2)
            {
                return(null);
            }

            switch (sourceType)
            {
            case 'S':
            case 'C':
            case 'L':
                if (sourceCode.Length < 5)
                {
                    return(null);
                }
                if (subType != 'P' && subType != 'A')
                {
                    return(null);
                }
                stateCode = sourceCode.Substring(hyphenPos + 1, 2);
                hyphenPos = 4;
                if (!StateCache.IsValidStateCode(stateCode))
                {
                    return(null);
                }
                break;

            case 'P':
                if (subType != 'M' && subType != 'C' && subType != 'S' && subType != 'V')
                {
                    return(null);
                }
                break;

            case 'A':
            case 'Z':
            case 'O':
                break;

            default:
                return(null);
            }

            var idString = sourceCode.Substring(hyphenPos + 1);

            if (!int.TryParse(idString, out var id) && sourceType != 'S')
            {
                return(null);
            }

            switch (sourceType)
            {
            case 'S':
                switch (subType)
                {
                case 'P':
                    return(States.GetContactEmail(stateCode));

                case 'A':
                    return(States.GetAltEmail(stateCode));
                }
                break;

            case 'C':
                switch (subType)
                {
                case 'P':
                    return(Counties.GetContactEmail(stateCode, idString));

                case 'A':
                    return(Counties.GetAltEmail(stateCode, idString));
                }
                break;

            case 'L':
                switch (subType)
                {
                case 'P':
                    return(LocalDistricts.GetContactEmail(stateCode, idString));

                case 'A':
                    return(LocalDistricts.GetAltEmail(stateCode, idString));
                }
                break;

            case 'P':
                switch (subType)
                {
                case 'M':
                    return(Politicians.GetEmailById(id));

                case 'C':
                    return(Politicians.GetCampaignEmailById(id));

                case 'S':
                    return(Politicians.GetStateEmailById(id));

                case 'V':
                    return(Politicians.GetEmailVoteUSAById(id));
                }
                break;

            case 'A':
                return(Addresses.GetEmailById(id));

            case 'Z':
                return(PartiesEmails.GetPartyEmailById(id));

            case 'O':
                return(OrganizationContacts.GetEmailByContactId(id));
            }

            return(null);
        }