public static CertificationMapping FindMatchingSeriesCertification(string country, string cert)
        {
            if (string.IsNullOrEmpty(country))
            {
                return(null);
            }
            CertificationMapping current = SERIES_CERTIFICATION_MAP.Where(c => c.CertificationId.Equals(cert, System.StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            IEnumerable <CertificationMapping> matches = null;
            CertificationMapping bestMatch             = null;

            if (current != null)
            {
                if (current.CountryCode == country)
                {
                    return(current);
                }
                matches = SERIES_CERTIFICATION_MAP.Where(c => c.CountryCode.Equals(country, System.StringComparison.InvariantCultureIgnoreCase) &&
                                                         c.AllowedAge >= current.AllowedAge && c.AllowedParentalGuidedAge >= current.AllowedParentalGuidedAge);
                if (matches != null)
                {
                    foreach (CertificationMapping match in matches)
                    {
                        if (bestMatch == null || bestMatch.AllowedAge > match.AllowedAge ||
                            (bestMatch.AllowedAge == match.AllowedAge && bestMatch.AllowedParentalGuidedAge > match.AllowedParentalGuidedAge))
                        {
                            bestMatch = match;
                        }
                    }
                }
            }
            return(bestMatch);
        }
        public static IEnumerable <CertificationMapping> FindAllAllowedSeriesCertifications(string cert)
        {
            CertificationMapping current = SERIES_CERTIFICATION_MAP.Where(c => c.CertificationId.Equals(cert, System.StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (current != null)
            {
                return(SERIES_CERTIFICATION_MAP.Where(c => c.AllowedAge <= current.AllowedAge && c.AllowedParentalGuidedAge <= current.AllowedParentalGuidedAge));
            }
            return(new List <CertificationMapping>());
        }
 public static bool IsAgeAllowed(CertificationMapping cert, int age, bool includeParentalGuided)
 {
     if (cert == null)
     {
         return(true);
     }
     if (cert.AllowedAge <= age && !includeParentalGuided)
     {
         return(true);
     }
     if (cert.AllowedParentalGuidedAge <= age && includeParentalGuided)
     {
         return(true);
     }
     return(false);
 }
 public static bool TryFindSeriesCertification(string country, string cert, out CertificationMapping certification)
 {
     return(TryFindCertification(SERIES_CERTIFICATION_MAP, country, cert, out certification));
 }
 public static bool TryFindMovieCertification(string country, string cert, out CertificationMapping certification)
 {
     return(TryFindCertification(MOVIE_CERTIFICATION_MAP, country, cert, out certification));
 }
        private static bool TryFindCertification(List <CertificationMapping> map, string country, string cert, out CertificationMapping certification)
        {
            certification = null;
            if (string.IsNullOrEmpty(cert))
            {
                return(false);
            }

            cert = cert.Trim();

            // For long strings like: "Rated PG for rude humor and mild action"
            if (cert.Length > 10)
            {
                certification = map.Where(c => (string.IsNullOrEmpty(country) || c.CountryCode.Equals(country, System.StringComparison.InvariantCultureIgnoreCase)) &&
                                          (c.CertificationId.Equals(cert, System.StringComparison.InvariantCultureIgnoreCase) ||
                                           c.Notations.Where(n => cert.StartsWith(n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.StartsWith(c.CountryCode + ":" + n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.StartsWith(GetCountryNotation(c.CountryCode) + ":" + n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.StartsWith(c.CountryCode + ": " + n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.StartsWith(GetCountryNotation(c.CountryCode) + ": " + n, System.StringComparison.InvariantCultureIgnoreCase)).Any())).FirstOrDefault();
            }
            else if (cert.Length > 0)
            {
                certification = map.Where(c => (string.IsNullOrEmpty(country) || c.CountryCode.Equals(country, System.StringComparison.InvariantCultureIgnoreCase)) &&
                                          (c.CertificationId.Equals(cert, System.StringComparison.InvariantCultureIgnoreCase) ||
                                           c.Notations.Where(n => cert.Equals(n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.Equals(c.CountryCode + ":" + n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.Equals(GetCountryNotation(c.CountryCode) + ":" + n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.Equals(c.CountryCode + ": " + n, System.StringComparison.InvariantCultureIgnoreCase) ||
                                                             cert.Equals(GetCountryNotation(c.CountryCode) + ": " + n, System.StringComparison.InvariantCultureIgnoreCase)).Any())).FirstOrDefault();
            }
            return(certification != null);
        }