Esempio n. 1
0
        public static string FindCountyCode()
        {
            // reworked to eliminate ViewState references
            var stateCode = FindStateCode();

            if (IsNullOrWhiteSpace(stateCode))
            {
                return(Empty);
            }

            var countyCode = QueryCounty;

            if (IsNullOrWhiteSpace(countyCode))
            {
                if (IsMasterUser || IsAdminUser)
                {
                    countyCode = UserCountyCode;
                    if (IsNullOrWhiteSpace(countyCode))
                    {
                        var localKey = FindLocalKey();
                        if (!IsNullOrEmpty(localKey))
                        {
                            // if there is a local key and there is no county in the query string,
                            // we must look up a county. If there's more than 1, we just use the first we find.
                            var counties = LocalIdsCodes.FindCounties(stateCode, localKey);
                            countyCode = counties.Length == 0 ? Empty : counties[0];
                        }
                        else
                        {
                            countyCode = Elections.GetCountyCodeFromKey(QueryElection);
                            if (IsNullOrWhiteSpace(countyCode))
                            {
                                countyCode = Offices.GetCountyCodeFromKey(QueryOffice);
                            }
                        }
                    }
                }
            }
            return(!IsNullOrWhiteSpace(countyCode) &&
                   CountyCache.CountyExists(stateCode, countyCode)
        ? countyCode
        : Empty);
        }
Esempio n. 2
0
        public static string County_Code()
        {
            var viewStateCountyCode = SecurePage.GetViewStateCountyCode();

            if (viewStateCountyCode != null)
            {
                return(viewStateCountyCode);
            }

            var countyCode = string.Empty;

            if (
                !VotePage.IsSessionStateEnabled ||
                !SecurePage.IsSignedIn
                )
            //if (db.Is_User_Anonymous())
            {
                if (!string.IsNullOrEmpty(VotePage.QueryElection))
                {
                    //could be old ElectionKey format
                    countyCode = Elections.GetCountyCodeFromKey(
                        //db.ElectionKey_New_Format(db.QueryString("Election")));
                        VotePage.QueryElection);
                }
                else if (!string.IsNullOrEmpty(VotePage.QueryOffice))
                {
                    countyCode = Offices.GetCountyCodeFromKey(VotePage.QueryOffice);
                }
                else if (!string.IsNullOrEmpty(VotePage.QueryCounty))
                {
                    countyCode = VotePage.QueryCounty;
                }
                if (
                    (countyCode == "000") || //Directory of Counties
                    (CountyCache.CountyExists(State_Code()
                                              , countyCode))
                    )
                {
                    return(countyCode);
                }
                return(string.Empty);
            }

            //only MASTER or State ADMIN can change CountyCode of county
            //Setting UserLocalCode empty resets to County level security

            if ((SecurePage.IsMasterUser || (SecurePage.IsStateAdminUser)) &&
                !string.IsNullOrEmpty(VotePage.QueryCounty)
                )
            {
                Session_Put("UserCountyCode", VotePage.QueryCounty);
                Session_Put("UserLocalCode", string.Empty);
            }
            else
            {
                //Need to reset CountyCode to empty
                //When there is a StateCode query string
                //but no CountyCode query string
                if (!string.IsNullOrEmpty(State_Code()))
                {
                    Session_Put("UserCountyCode", string.Empty);
                    Session_Put("UserLocalCode", string.Empty);
                }
            }

            if (CountyCache.CountyExists(
                    State_Code()
                    , User_CountyCode()))
            {
                return(User_CountyCode());
            }
            return(string.Empty);
        }