private static void GetDefaultAgeBand(SiteConfigurationData siteConfig, out ConfigurationAgeBand configurationAgeBand, out string configurationAgeBandKey)
    {
        Compliance compliance = siteConfig.compliance;

        configurationAgeBand    = DictionaryUtils.TryGetValue(compliance.ageBands, compliance.defaultAgeBand);
        configurationAgeBandKey = compliance.defaultAgeBand;
    }
    private static IAgeBand CreateAgeBand(SiteConfigurationData siteConfig, ConfigurationAgeBand configurationAgeBand, string configurationAgeBandKey, bool registration, IList <RegistrationText> legalTexts)
    {
        IRegistrationPermissions     permissions             = CreateRegistrationPermissions(registration ? configurationAgeBand.CREATE : configurationAgeBand.UPDATE);
        IEnumerable <ILegalDocument> legalDocuments          = BuildLegalDocs(siteConfig.legal, configurationAgeBandKey, registration, legalTexts);
        IEnumerable <string>         legalDocumentsTypeOrder = GetLegalDocumentsTypeOrder(siteConfig.legal, configurationAgeBandKey);
        IEnumerable <IMarketingItem> marketing = BuildMarketingItems(siteConfig, configurationAgeBandKey, registration, legalTexts);
        AgeBandType type    = AgeBandTypeConverter.Convert(configurationAgeBandKey);
        string      country = configurationAgeBand.country;

        return(new AgeBand(permissions, legalDocuments, legalDocumentsTypeOrder, marketing, type, country));
    }
    private void GetRegistrationText(SiteConfigurationData siteConfig, ConfigurationAgeBand configurationAgeBand, string configurationAgeBandKey, string languageCode, bool registration, Action <IGetAgeBandResult> callback)
    {
        List <string> documentIds = GetAllTextIds(siteConfig, configurationAgeBandKey, registration);

        if (documentIds.Count == 0)
        {
            HandleRequestSuccess(siteConfig, configurationAgeBand, configurationAgeBandKey, registration, new List <RegistrationText>(), callback);
        }
        else
        {
            try
            {
                GetRegistrationTextRequest getRegistrationTextRequest = new GetRegistrationTextRequest();
                getRegistrationTextRequest.LanguageCode = languageCode;
                getRegistrationTextRequest.TextCodes    = documentIds;
                getRegistrationTextRequest.CountryCode  = configurationAgeBand.country;
                getRegistrationTextRequest.AgeBand      = configurationAgeBandKey;
                GetRegistrationTextRequest request = getRegistrationTextRequest;
                IWebCall <GetRegistrationTextRequest, GetRegistrationTextResponse> webCall = webCallFactory.RegistrationTextPost(request);
                webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetRegistrationTextResponse> e)
                {
                    GetRegistrationTextResponse response = e.Response;
                    if (ValidateResponse(response, documentIds))
                    {
                        HandleRequestSuccess(siteConfig, configurationAgeBand, configurationAgeBandKey, registration, response.RegistrationText, callback);
                    }
                    else
                    {
                        callback(new GetAgeBandResult(success: false, null));
                    }
                };
                webCall.OnError += delegate
                {
                    callback(new GetAgeBandResult(success: false, null));
                };
                webCall.Execute();
            }
            catch (Exception arg)
            {
                logger.Critical("Unhandled exception: " + arg);
                callback(new GetAgeBandResult(success: false, null));
            }
        }
    }
 private static void GetAgeBandByAge(SiteConfigurationData siteConfig, int age, out ConfigurationAgeBand configurationAgeBand, out string configurationAgeBandKey)
 {
     configurationAgeBand    = null;
     configurationAgeBandKey = null;
     foreach (KeyValuePair <string, ConfigurationAgeBand> ageBand in siteConfig.compliance.ageBands)
     {
         string key = ageBand.Key;
         ConfigurationAgeBand value = ageBand.Value;
         if (value != null && age >= value.minAge && age <= value.maxAge && ValidateAgeBandKey(key))
         {
             LegalGroup legalGroup = DictionaryUtils.TryGetValue(siteConfig.legal, key);
             if (legalGroup != null)
             {
                 configurationAgeBand    = value;
                 configurationAgeBandKey = key;
             }
         }
     }
 }
    private static void GetAgeBandByKey(SiteConfigurationData siteConfig, string ageBandKey, out ConfigurationAgeBand configurationAgeBand, out string configurationAgeBandKey)
    {
        configurationAgeBand    = null;
        configurationAgeBandKey = null;
        if (!ValidateAgeBandKey(ageBandKey))
        {
            return;
        }
        ConfigurationAgeBand configurationAgeBand2 = DictionaryUtils.TryGetValue(siteConfig.compliance.ageBands, ageBandKey);

        if (configurationAgeBand2 != null)
        {
            LegalGroup legalGroup = DictionaryUtils.TryGetValue(siteConfig.legal, ageBandKey);
            if (legalGroup != null)
            {
                configurationAgeBand    = configurationAgeBand2;
                configurationAgeBandKey = ageBandKey;
            }
        }
    }
    private static void HandleRequestSuccess(SiteConfigurationData siteConfig, ConfigurationAgeBand configurationAgeBand, string configurationAgeBandKey, bool registration, IList <RegistrationText> legalTexts, Action <IGetAgeBandResult> callback)
    {
        IAgeBand ageBand = CreateAgeBand(siteConfig, configurationAgeBand, configurationAgeBandKey, registration, legalTexts);

        callback(new GetAgeBandResult(ageBand != null, ageBand));
    }
 private static void GetConfigurationAgeBand(SiteConfigurationData siteConfig, string ageBandKey, int age, out ConfigurationAgeBand configurationAgeBand, out string configurationAgeBandKey)
 {
     if (ageBandKey != null)
     {
         GetAgeBandByKey(siteConfig, ageBandKey, out configurationAgeBand, out configurationAgeBandKey);
         if (configurationAgeBand != null)
         {
             return;
         }
     }
     GetAgeBandByAge(siteConfig, age, out configurationAgeBand, out configurationAgeBandKey);
     if (configurationAgeBand == null)
     {
         GetDefaultAgeBand(siteConfig, out configurationAgeBand, out configurationAgeBandKey);
     }
 }