private IEnumerable<StrainPercentiles> GetPercentileViews(PreferencesView preferences)
 {
     return (from traitVM in preferences.Preferences
             where traitVM.Percentile
             select GetOnePercentileView(preferences.Strain, preferences.SaleYear, traitVM.BullSaleView))
             .ToList();
 }
        public SearchResults BullSearch(PreferencesView preferences, AvailabilityScope availabilityScope, SaleStatusScope saleStatus, int basketSize)
        {
            var results = new SearchResults
                {
                    StrainPercentiles = GetPercentileViews(preferences)
                };

            var searcher = new Search(
                _salebullRepository.Get(preferences.Strain, Convert.ToInt16(preferences.SaleYear), availabilityScope, saleStatus),
                preferences.Preferences, results.StrainPercentiles
                );

            var qualifiedBulls = searcher.QualifyBulls();
            
            // set number total and sequenced matches
            foreach (var qualifiedBull in qualifiedBulls)
            {
                qualifiedBull.TotalMatches= qualifiedBull.BullTraits.Count(x => x.Qualifies);
                qualifiedBull.SequencedMatches = CountSequencedMatches(qualifiedBull.BullTraits);
            }


            //var temp = qualifiedBulls.Where(x => x.SequencedMatches > 0).ToList();

            results.QualifiedBulls = qualifiedBulls
                .OrderByDescending(x => x.SequencedMatches)
                .ThenByDescending(x => x.Bull.SEL_IDX)
                .Take(basketSize)
                .ToList();

            return results;
        }