Пример #1
0
        public SearchResults Search(SearchOptions options)
        {
            // Intitialize Search result
            SearchResults results = new SearchResults()
            {
                ColorCounts = new List <ColorCount>(),
                SizeCounts  = new List <SizeCount>(),
                Shirts      = new List <Shirt>()
            };

            List <Shirt> colourMatchedShirts = new List <Shirt>();

            if (options != null)
            {
                foreach (Color color in options.Colors)
                {
                    ColorCount colorCount = new ColorCount()
                    {
                        Color = color, Count = 0
                    };

                    foreach (Size size in Size.All)
                    {
                        colourMatchedShirts = _shirts.FindAll(item => (item.Color.Name.Equals(color.Name)) && (item.Size.Name.Equals(size.Name)));

                        // Search when sizes are specified
                        if (options.Sizes.Contains(size) && options.Sizes.Count > 0)
                        {
                            if (colourMatchedShirts.Count > 0)
                            {
                                colorCount.Count += colourMatchedShirts.Count;
                                results.Shirts.AddRange(colourMatchedShirts);
                                SizeCount sizeCount = results.SizeCounts.Find(item => item.Size.Name.Equals(size.Name));
                                if (sizeCount == null)
                                {
                                    results.SizeCounts.Add(new SizeCount {
                                        Size = size, Count = colourMatchedShirts.Count
                                    });
                                }
                                else
                                {
                                    sizeCount.Count++;
                                }
                            }
                        }
                        else if (options.Sizes.Count == 0)
                        {
                            // Count all sizes
                            colorCount.Count += colourMatchedShirts.Count;
                        }
                    }
                    results.ColorCounts.Add(colorCount);
                }
            }

            return(results);
        }
 private static void DefaultSize(List <SizeCount> sizeCounts)
 {
     foreach (var item in Size.All)
     {
         var sizeCount = new SizeCount {
             Size = item, Count = 0
         };
         if (!sizeCounts.Where(x => x.Size.Id == item.Id).Any())
         {
             sizeCounts.Add(sizeCount);
         }
     }
 }
Пример #3
0
        private IList <SizeCount> GetSizeCounts()
        {
            var sizeCounts = new List <SizeCount>();

            foreach (var size in _sizeSetsDictionary.Keys)
            {
                var actualCount = _sizeSetsDictionary[size].Count;
                var sizeCount   = new SizeCount {
                    Count = actualCount, Size = size
                };
                sizeCounts.Add(sizeCount);
            }

            return(sizeCounts);
        }
        public IList <SizeCount> GetSizeCounts()
        {
            var sizeCounts = new List <SizeCount>();

            foreach (var size in _countMap.Keys)
            {
                var actualCount = _countMap[size];
                var sizeCount   = new SizeCount {
                    Count = actualCount, Size = size
                };
                sizeCounts.Add(sizeCount);
            }

            return(sizeCounts);
        }
Пример #5
0
        /// <summary>
        /// Getting quantity of shirts having sizes matching search options combined with their object
        /// </summary>
        /// <param name="options">Search options</param>
        /// <returns>List of sizes with their quantities</returns>
        private List <SizeCount> GetShirtsOfSize(SearchOptions options)
        {
            List <SizeCount> shirtsOfSize = new List <SizeCount>();

            foreach (Size size in Size.All)
            {
                SizeCount sizeCount = new SizeCount();

                sizeCount.Size = size;
                foreach (Color color in options.Colors)
                {
                    sizeCount.Count = _shirtSizeGroup[size].Colors[color].Shirts.Count;
                }
                shirtsOfSize.Add(sizeCount);
            }

            return(shirtsOfSize);
        }
Пример #6
0
        public SearchResults Search(SearchOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(Constants.ParamNotProvidedExceptionMessage);
            }

            var searchColors = options.Colors.Count == 0 ? Color.All : options.Colors;
            var searchsizes  = options.Sizes.Count == 0?Size.All: options.Sizes;

            var searchResul = new SearchResults
            {
                ColorCounts = Color.All.Select(color => new ColorCount {
                    Color = color
                }).ToList(),
                SizeCounts = Size.All.Select(size => new SizeCount {
                    Size = size
                }).ToList(),
                Shirts = new List <Shirt>()
            };

            foreach (var size in searchsizes)
            {
                if (_shirtCollection.ShirtSizes.ContainsKey(size))
                {
                    ShirtSize colorSizesShirt = _shirtCollection.ShirtSizes[size];
                    foreach (var color in searchColors)
                    {
                        var       colorCount = searchResul.ColorCounts.First(x => x.Color == color);
                        SizeCount sizeCount  = searchResul.SizeCounts.First(s => s.Size == size);
                        if (colorSizesShirt.ShirtColors.ContainsKey(color))
                        {
                            searchResul.Shirts.AddRange(colorSizesShirt.ShirtColors[color].Shirts);
                            sizeCount.Count  += colorSizesShirt.ShirtColors[color].Shirts.Count;
                            colorCount.Count += colorSizesShirt.ShirtColors[color].Shirts.Count;
                        }
                    }
                }
            }

            return(searchResul);
        }
Пример #7
0
        public static void UpdateCounts(SearchResults searchResult, SearchOptions options)
        {
            searchResult.ColorCounts = new List <ColorCount>();
            searchResult.SizeCounts  = new List <SizeCount>();

            Color.All.ForEach(r =>
            {
                var colorCount = new ColorCount()
                {
                    Color = r, Count = searchResult.Shirts.Where(x => x.Color == r).Count()
                };
                searchResult.ColorCounts.Add(colorCount);
            });

            Size.All.ForEach(r =>
            {
                var sizeCount = new SizeCount()
                {
                    Size = r, Count = searchResult.Shirts.Where(x => x.Size == r).Count()
                };
                searchResult.SizeCounts.Add(sizeCount);
            });
        }
Пример #8
0
        public SearchResults LookupSearch(SearchOptions options)
        {
            //Intitialize search result
            SearchResults results = new SearchResults()
            {
                ColorCounts = new List <ColorCount>(),
                SizeCounts  = new List <SizeCount>(),
                Shirts      = new List <Shirt>()
            };

            // Convert to Lookup
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var shirtsLookup = _shirts.ToLookup(x => new { x.Color, x.Size });

            sw.Stop();
            results.Milliseconds = sw.ElapsedMilliseconds;

            //Search
            if (options != null)
            {
                foreach (Color color in options.Colors)
                {
                    ColorCount colorCount = new ColorCount()
                    {
                        Color = color, Count = 0
                    };

                    foreach (Size sz in Size.All)
                    {
                        var colourMatchedShirts = shirtsLookup[new { Color = color, Size = sz }];
                        if (options.Sizes.Contains(sz) && options.Sizes.Count > 0)
                        {
                            if (colourMatchedShirts.Count() > 0)
                            {
                                colorCount.Count += colourMatchedShirts.Count();
                                results.Shirts.AddRange(colourMatchedShirts.ToList <Shirt>());
                                SizeCount sizeCount = results.SizeCounts.Find(item => item.Size.Name.Equals(sz.Name));
                                if (sizeCount == null)
                                {
                                    results.SizeCounts.Add(new SizeCount {
                                        Size = sz, Count = colourMatchedShirts.Count()
                                    });
                                }
                                else
                                {
                                    sizeCount.Count++;
                                }
                            }
                        }
                        else if (options.Sizes.Count == 0)
                        {
                            colorCount.Count += colourMatchedShirts.Count();
                        }
                    }
                    results.ColorCounts.Add(colorCount);
                }
            }
            return(results);
        }