/// <summary>
        /// Get list of protected taxons. List is cached.
        /// </summary>
        /// <returns>Protected taxons.</returns>
        public IEnumerable <ITaxon> GetProtectedTaxons()
        {
            const string CachedProtectedTaxons = "protectedTaxons";

            IEnumerable <ITaxon> protectedTaxons = (IEnumerable <ITaxon>)AspNetCache.GetCachedObject(CachedProtectedTaxons);

            if (protectedTaxons.IsNull())
            {
                ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

                searchCriteria.IncludeNotValidHosts = false;
                searchCriteria.IncludeNotValidTaxa  = false;
                searchCriteria.Factors = new FactorList();

                IFactor factor = CoreData.FactorManager.GetFactor(_user, FactorId.ProtectionLevel);

                searchCriteria.Factors.Add(factor);

                searchCriteria.FieldSearchCriteria = new SpeciesFactFieldSearchCriteriaList();

                ISpeciesFactFieldSearchCriteria fieldSearchCriteria = new SpeciesFactFieldSearchCriteria();
                fieldSearchCriteria.FactorField = factor.DataType.Field1;
                fieldSearchCriteria.Operator    = CompareOperator.Greater;
                fieldSearchCriteria.AddValue(1);

                searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);

                // Get species facts related to protected taxons
                SpeciesFactList speciesFactList = CoreData.SpeciesFactManager.GetSpeciesFacts(_user, searchCriteria);

                // Get distinct list of taxons from list of species facts
                protectedTaxons = speciesFactList.Select(sf => sf.Taxon).Distinct();

                AspNetCache.AddCachedObject(
                    CachedProtectedTaxons,
                    protectedTaxons,
                    DateTime.Now.AddHours(6),
                    System.Web.Caching.CacheItemPriority.Normal);
            }

            return(protectedTaxons);
        }
        /// <summary>
        /// Search for list of taxon by factor.
        /// </summary>
        /// <param name="taxonSearchFactorFieldViewModels"></param>
        /// <param name="factorId"></param>
        /// <param name="restrictToCurrentTaxonFilter"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        private List <ITaxon> SearchTaxonByFactor(List <TaxonSearchFactorFieldViewModel> taxonSearchFactorFieldViewModels, Int32 factorId, Boolean restrictToCurrentTaxonFilter, MySettings.MySettings settings)
        {
            if (taxonSearchFactorFieldViewModels == null)
            {
                taxonSearchFactorFieldViewModels = new List <TaxonSearchFactorFieldViewModel>();
            }

            TaxonList taxonList = new TaxonList();
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.IncludeNotValidHosts = false;
            searchCriteria.IncludeNotValidTaxa  = false;
            searchCriteria.FieldSearchCriteria  = new SpeciesFactFieldSearchCriteriaList();
            searchCriteria.Factors = new FactorList();
            ISpeciesFactFieldSearchCriteria fieldSearchCriteria;

            searchCriteria.FieldLogicalOperator = LogicalOperator.And;

            if (taxonSearchFactorFieldViewModels.Count > 0)
            {
                if (restrictToCurrentTaxonFilter)
                {
                    if (settings.Filter.Taxa.HasSettings)
                    {
                        searchCriteria.Taxa = CoreData.TaxonManager.GetTaxa(_user, settings.Filter.Taxa.TaxonIds.ToList());
                    }
                    else
                    {
                        return(new TaxonList());
                    }
                }

                IFactor factor = CoreData.FactorManager.GetFactor(_user, factorId);

                searchCriteria.Factors.Add(factor);

                // Add factor field to search criteria by list of factor field id
                foreach (var field in factor.DataType.Fields)
                {
                    if (field.Type.Id == (int)FactorFieldDataTypeId.Enum)
                    {
                        if (field.Enum != null && field.Enum.Values != null)
                        {
                            fieldSearchCriteria = new SpeciesFactFieldSearchCriteria();
                            // fieldSearchCriteria.IsEnumAsString = true;
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = CompareOperator.Equal;
                            foreach (var val in field.Enum.Values)
                            {
                                if (val.KeyInt.HasValue && taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == val.Id))
                                {
                                    String factorValue = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == val.Id).FactorFieldTypeValue;
                                    fieldSearchCriteria.AddValue(factorValue);
                                }
                            }

                            if (fieldSearchCriteria.Values.IsNotEmpty())
                            {
                                searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                            }
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.Boolean)
                    {
                        if (field.Enum != null && field.Enum.Values != null)
                        {
                            fieldSearchCriteria = new SpeciesFactFieldSearchCriteria();
                            // fieldSearchCriteria.IsEnumAsString = true;
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = CompareOperator.Equal;
                            foreach (var val in field.Enum.Values)
                            {
                                if (val.KeyInt.HasValue && taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == val.Id))
                                {
                                    String factorValue = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == val.Id).FactorFieldTypeValue;
                                    fieldSearchCriteria.AddValue(factorValue);
                                }
                            }

                            if (fieldSearchCriteria.Values.IsNotEmpty())
                            {
                                searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                            }
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.Double)
                    {
                        if (taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == field.Id))
                        {
                            TaxonSearchFactorFieldViewModel factorField = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == field.Id);
                            CompareOperator compareOperator             = factorField.CompareOperatorIsSpecified ? factorField.CompareOperator : CompareOperator.Equal;
                            String          factorValue = factorField.FactorFieldTypeValue;
                            fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = compareOperator;
                            fieldSearchCriteria.AddValue(factorValue.WebParseInt32());
                            searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.Int32)
                    {
                        if (taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == field.Id))
                        {
                            TaxonSearchFactorFieldViewModel factorField = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == field.Id);
                            CompareOperator compareOperator             = factorField.CompareOperatorIsSpecified ? factorField.CompareOperator : CompareOperator.Equal;
                            String          factorValue = factorField.FactorFieldTypeValue;
                            fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = compareOperator;
                            fieldSearchCriteria.AddValue(factorValue.WebParseInt32());
                            searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                        }
                    }
                    else if (field.Type.Id == (int)FactorFieldDataTypeId.String)
                    {
                        if (taxonSearchFactorFieldViewModels.Any(x => x.FactorFieldTypeId == field.Id))
                        {
                            TaxonSearchFactorFieldViewModel factorField = taxonSearchFactorFieldViewModels.First(x => x.FactorFieldTypeId == field.Id);
                            CompareOperator compareOperator             = factorField.CompareOperatorIsSpecified ? factorField.CompareOperator : CompareOperator.Equal;
                            String          factorValue = factorField.FactorFieldTypeValue;
                            fieldSearchCriteria             = new SpeciesFactFieldSearchCriteria();
                            fieldSearchCriteria.FactorField = field;
                            fieldSearchCriteria.Operator    = compareOperator;
                            fieldSearchCriteria.AddValue(factorValue);
                            searchCriteria.FieldSearchCriteria.Add(fieldSearchCriteria);
                        }
                    }
                }
            }
            else
            {
                return(new TaxonList());
            }

            // Get taxa.
            taxonList = CoreData.AnalysisManager.GetTaxa(_user, searchCriteria);

            return(taxonList);
        }