Esempio n. 1
0
        private List <SizeFacetViewModel> GetAllDifferentSizeFacets(IEnumerable <TermCount> facetResult, List <string> selectedSizes)
        {
            List <SizeFacetViewModel> allDifferentSizeFacets = new List <SizeFacetViewModel>();

            foreach (var sizeFacet in facetResult.OrderBy(x => SortSizes(x.Term)))
            {
                string   term        = sizeFacet.Term.ToLower();
                string[] typeAndSize = term.Split('/');
                string   sizeType    = typeAndSize[0];
                string   size        = typeAndSize[1];
                if (typeAndSize.Length == 3)
                {
                    sizeType = typeAndSize[1];
                    size     = typeAndSize[2];
                }

                bool newSizeTypeList        = true;
                SizeFacetViewModel sizeList = allDifferentSizeFacets.FirstOrDefault(x => x.SizeUnit == sizeType);
                if (sizeList == null)
                {
                    sizeList            = new SizeFacetViewModel();
                    sizeList.SizeUnit   = sizeType;
                    sizeList.SizeFacets = new List <FacetViewModel>();
                }
                else
                {
                    newSizeTypeList = false;
                }
                // check for duplicate entry and join them
                var facetViewModel = sizeList.SizeFacets.FirstOrDefault(x => x.Name == term);
                if (facetViewModel == null)
                {
                    facetViewModel       = new FacetViewModel();
                    facetViewModel.Name  = term;
                    facetViewModel.Size  = size;
                    facetViewModel.Count = sizeFacet.Count;
                    sizeList.SizeFacets.Add(facetViewModel);
                }
                else
                {
                    facetViewModel.Count += sizeFacet.Count;
                }
                facetViewModel.Selected = selectedSizes != null && selectedSizes.Contains(term);

                if (sizeList.SizeFacets.Any(x => x.Selected.Equals(true)))
                {
                    sizeList.SomeIsSelected = true;
                }
                if (newSizeTypeList)
                {
                    allDifferentSizeFacets.Add(sizeList);
                }
            }
            return(allDifferentSizeFacets);
        }
        private List<SizeFacetViewModel> GetAllDifferentSizeFacets(IEnumerable<TermCount> facetResult, List<string> selectedSizes)
        {
            List<SizeFacetViewModel> allDifferentSizeFacets = new List<SizeFacetViewModel>();

            foreach (var sizeFacet in facetResult.OrderBy(x => SortSizes(x.Term)))
            {
                string term = sizeFacet.Term.ToLower();
                string[] typeAndSize = term.Split('/');
                string sizeType = typeAndSize[0];
                string size = typeAndSize[1];
                if (typeAndSize.Length == 3)
                {
                    sizeType = typeAndSize[1];
                    size = typeAndSize[2];
                }

                bool newSizeTypeList = true;
                SizeFacetViewModel sizeList = allDifferentSizeFacets.FirstOrDefault(x => x.SizeUnit == sizeType);
                if (sizeList == null)
                {
                    sizeList = new SizeFacetViewModel();
                    sizeList.SizeUnit = sizeType;
                    sizeList.SizeFacets = new List<FacetViewModel>();
                }
                else
                {
                    newSizeTypeList = false;
                }
                // check for duplicate entry and join them
                var facetViewModel = sizeList.SizeFacets.FirstOrDefault(x => x.Name == term);
                if (facetViewModel == null)
                {
                    facetViewModel = new FacetViewModel();
                    facetViewModel.Name = term;
                    facetViewModel.Size = size;
                    facetViewModel.Count = sizeFacet.Count;
                    sizeList.SizeFacets.Add(facetViewModel);
                }
                else
                {
                    facetViewModel.Count += sizeFacet.Count;
                }
                facetViewModel.Selected = selectedSizes != null && selectedSizes.Contains(term);

                if (sizeList.SizeFacets.Any(x => x.Selected.Equals(true)))
                {
                    sizeList.SomeIsSelected = true;
                }
                if (newSizeTypeList)
                {
                    allDifferentSizeFacets.Add(sizeList);
                }
            }
            return allDifferentSizeFacets;
        }