Esempio n. 1
0
        private void PopulateRegionsToAppellations()
        {
            if (_allRegions != null) {

                foreach (var region in _allRegions) {

                    string regionName = region.Name;
                    int regionId = region.Id;

                    if (regionId == FAUX_CATEGORY_NO_SELECTION) {
                        continue;
                    }

                    var categoryMapService = new CategoryMapService();
                    categoryMapService.CategoriesFilter(CATEGORY_SHOP, regionId);
                    var categoryMap = categoryMapService.Execute();

                    var matchingAppellations = (from c in categoryMap.Categories where c.Id == CATEGORY_APPELATIONS select c).FirstOrDefault();
                    if (matchingAppellations != null) {
                        var orderedMatchingAppellations = (from r in matchingAppellations.Refinements orderby r.Name select r).ToArray();
                        var appellations = new List<Refinement>();
                        appellations.Add(_noSelectionAppellations);
                        appellations.AddRange(orderedMatchingAppellations);
                        _regionsToAppellations.Add(regionId, appellations.ToArray());
                    }
                    else {
                        Refinement dummyAppellation = new Refinement();
                        dummyAppellation.Id = FAUX_CATEGORY_DUMMY_APPELLATION;
                        dummyAppellation.Name = regionName;
                        dummyAppellation.Url = string.Empty;
                        _regionsToAppellations.Add(regionId, new Refinement[] { _noSelectionAppellations, dummyAppellation });
                    }
                }

                // Now we can go ahead and build _allAppellations.

                var alphabeticalRegions = (from rr in _allRegions orderby rr.Name where rr.Id != FAUX_CATEGORY_NO_SELECTION select rr).ToArray();

                var allAppellations = new List<Refinement>();
                allAppellations.Add(_noSelectionAppellations);
                foreach (var region in alphabeticalRegions) {
                    int regionId = region.Id;
                    var appellations1 = _regionsToAppellations[regionId];
                    if (appellations1 != null) {
                        var appellations2 = (from ar in appellations1 where ar.Id != FAUX_CATEGORY_NO_SELECTION select ar).ToArray();
                        allAppellations.AddRange(appellations2);
                    }
                }
                _allAppellations = allAppellations;
            }
        }
Esempio n. 2
0
        private void PopulateWineTypesToVarietals()
        {
            if (_allWineTypes != null) {

                foreach (var wineType in _allWineTypes) {

                    string wineTypeName = wineType.Name;
                    int wineTypeId = wineType.Id;

                    if (wineTypeId == FAUX_CATEGORY_NO_SELECTION) {
                        continue;
                    }

                    var categoryMapService = new CategoryMapService();
                    categoryMapService.CategoriesFilter(CATEGORY_SHOP, wineTypeId);
                    var categoryMap = categoryMapService.Execute();

                    var matchingVarietals = (from c in categoryMap.Categories where c.Id == CATEGORY_VARIETALS select c).FirstOrDefault();
                    if (matchingVarietals != null) {
                        var varietals = new List<Refinement>();
                        varietals.Add(_noSelectionVarietals);
                        varietals.AddRange(matchingVarietals.Refinements);
                        _wineTypesToVarietals.Add(wineTypeId, varietals.ToArray());
                    }
                }
            }
        }
Esempio n. 3
0
        private void PopulateFullLists()
        {
            var categoryMapService = new CategoryMapService();
            categoryMapService.CategoriesFilter(CATEGORY_SHOP);
            var categoryMap = categoryMapService.Execute();

            var wineTypeCategory = (from c in categoryMap.Categories where c.Id == CATEGORY_WINETYPES select c).FirstOrDefault();
            if (wineTypeCategory != null) {
                // Wine types seem to be presented in the order that they are returned in.
                var wineTypes = new List<Refinement>();
                wineTypes.Add(_noSelectionWineTypes);
                wineTypes.AddRange(wineTypeCategory.Refinements);
                _wineTypes = _allWineTypes = wineTypes;
            }

            var varietalCategory = (from c in categoryMap.Categories where c.Id == CATEGORY_VARIETALS select c).FirstOrDefault();
            if (varietalCategory != null) {
                // All Varietals seem to be ordered by Id.
                var orderedVarietals = (from r in varietalCategory.Refinements orderby r.Id select r).ToArray();
                var varietals = new List<Refinement>();
                varietals.Add(_noSelectionVarietals);
                varietals.AddRange(orderedVarietals);
                _varietals = _allVarietals = varietals;
            }

            var regionCategory = (from c in categoryMap.Categories where c.Id == CATEGORY_REGIONS select c).FirstOrDefault();
            if (regionCategory != null) {
                // All Regions seem to be presented in the order that they are returned in.
                var regions = new List<Refinement>();
                regions.Add(_noSelectionRegions);
                regions.AddRange(regionCategory.Refinements);
                _regions = _allRegions = regions;
            }

            var appellationCategory = (from c in categoryMap.Categories where c.Id == CATEGORY_APPELATIONS select c).FirstOrDefault();
            if (appellationCategory != null) {
                // All Appellations seems to be ordered as follows:
                //
                //  "All Appellations"
                //  Alphabetical list of appellations for the first region
                //  Alphabetical list of appellations for the second region
                //  ...
                //
                // where the regions are themselves ordered alphabetically.
                // An oddity is that "Greece", "Portugal" and "South Africa" are listed as appellations but "Canada" is not.
                //
                // Hence, we build _allAppellations in PopulateRegionsToAppellations() below.
            }
        }