private IList <GrouponAttribute> FillAttributesByCategory(string category,
                                                                  IList <FeatureValueDTO> features,
                                                                  string description,
                                                                  string title,
                                                                  string color,
                                                                  string size)
        {
            var results = new List <GrouponAttribute>();

            if (StringHelper.IsEqualNoCase(category, "Apparel_Boys'_Underwear"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }
            if (StringHelper.IsEqualNoCase(category, "Apparel_Girls'_Underwear"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Men's_Shorts_Denim") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Men's_Shorts_Denims"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Men's Apparel Size",
                    Value = GrouponUtils.PrepareMensApparelSize(size),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Men's_Shirts_Dress Shirts"))
            {
                /*Classic
                 * Modern
                 * Relaxed
                 * Slim
                 */
                results.Add(new GrouponAttribute()
                {
                    Name  = "BUTTON DOWN SHIRT FIT",
                    Value = "Classic",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Men's Apparel Size",
                    Value = GrouponUtils.PrepareMensApparelSize(size),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }


            if (StringHelper.IsEqualNoCase(category, "Apparel_Women's_Intimates_Slips"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "BRA AND UNDERGARMENT MATERIALS",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "INTIMATES TYPE",
                    Value = "Pajamas",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }
            if (StringHelper.IsEqualNoCase(category, "Apparel_Men's_Underwear_Collections & Sets"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "BRA AND UNDERGARMENT MATERIALS",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Men's Apparel Size",
                    Value = GrouponUtils.PrepareMensApparelSize(size),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Women's_Sleep & Lounge_Onesies"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "INTIMATES TYPE",
                    Value = "Pajamas",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "LOUNGE & SLEEPWEAR TYPE",
                    Value = "Pajama Sets"

                            /*Loungewear
                             * Nightshirts
                             * Pajama Bottoms (Shorts & Pants)
                             * Pajama Sets
                             * Pajamas Bottoms (Shorts & Pants)
                             */
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Women's Apparel Size",
                    Value = GrouponUtils.PrepareSize(size),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Women's_Sleep & Lounge_Nightgowns & Sleepshirts") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Women's_Sleep & Lounge_Sleep Sets") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Women's_Sleep & Lounge_Sleep Bottoms") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Women's_Sleep & Lounge_Robes"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "APPAREL AND FOOTWEAR MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "INTIMATES TYPE",
                    Value = "Pajamas",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "LOUNGE & SLEEPWEAR TYPE",
                    Value = "Pajama Sets"

                            /*Loungewear
                             * Nightshirts
                             * Pajama Bottoms (Shorts & Pants)
                             * Pajama Sets
                             * Pajamas Bottoms (Shorts & Pants)
                             */
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Women's Apparel Size",
                    Value = GrouponUtils.PrepareMensApparelSize(size),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Men's_Sleep & Lounge_Sleep Sets") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Men's_Sleep & Lounge_Sleep Tops") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Men's_Sleep & Lounge_Sleep Bottoms") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Men's_Sleep & Lounge_Robes"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "APPAREL AND FOOTWEAR MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "LOUNGE & SLEEPWEAR TYPE",
                    Value = "Pajama Sets"

                            /*Loungewear
                             * Nightshirts
                             * Pajama Bottoms (Shorts & Pants)
                             * Pajama Sets
                             * Pajamas Bottoms (Shorts & Pants)
                             */
                });

                results.Add(new GrouponAttribute()
                {
                    Name  = "Men's Apparel Size",
                    Value = GrouponUtils.PrepareMensApparelSize(size),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Boys'_Sleepwear_Gowns"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "MADE IN USA",
                    Value = "N"
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }
            if (StringHelper.IsEqualNoCase(category, "Apparel_Girls'_Sleepwear_Gowns"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Boys'_Pajamas") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Girls'_Pajamas"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "BABY CLOTHING AND ACCESSORY MATERIALS",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Children's Apparel Size",
                    Value = size,
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Color",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "MADE IN USA",
                    Value = "N"
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            if (StringHelper.IsEqualNoCase(category, "Apparel_Boys'_Bath_Robes") ||
                StringHelper.IsEqualNoCase(category, "Apparel_Girls'_Bath_Robes"))
            {
                results.Add(new GrouponAttribute()
                {
                    Name  = "CARE INSTRUCTIONS",
                    Value = "Label",
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "Children's Apparel Size",
                    Value = size,
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "COLOR",
                    Value = GrouponUtils.PrepareColor(StringHelper.GetFirstNotEmpty(color, features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value)),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "FABRIC/MATERIAL",
                    Value = StringHelper.IfEmpty(features.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value, "n/a"),
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "MADE IN USA",
                    Value = "N"
                });
                results.Add(new GrouponAttribute()
                {
                    Name  = "SIZING CHART",
                    Value = "Standard",
                });
            }

            return(results);
        }
        private IList <GrouponGoodLine> BuildProductLines(IList <ItemExDTO> allItems,
                                                          IList <ParentItemDTO> allParentItems,
                                                          IList <StyleEntireDto> allStyles,
                                                          IList <StyleImageDTO> allStyleImages,
                                                          IList <StyleItemDTO> allStyleItems,
                                                          IList <FeatureValueDTO> allFeatures)
        {
            var results = new List <GrouponGoodLine>();

            foreach (var parentItem in allParentItems)
            {
                var items = allItems.Where(i => i.ParentASIN == parentItem.ASIN).ToList();

                foreach (var item in items)
                {
                    var style         = allStyles.FirstOrDefault(s => s.Id == item.StyleId);
                    var styleItem     = allStyleItems.FirstOrDefault(si => si.StyleItemId == item.StyleItemId);
                    var styleImages   = allStyleImages.Where(si => si.StyleId == style.Id && !si.IsSystem).ToList();
                    var styleFeatures = allFeatures.Where(f => f.StyleId == item.StyleId).ToList();

                    var gender              = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.GENDER)?.Value;
                    var subLicense          = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.SUB_LICENSE1)?.Value;
                    var mainLicense         = StyleFeatureHelper.PrepareMainLicense(styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MAIN_LICENSE)?.Value, subLicense);
                    var material            = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.MATERIAL)?.Value;
                    var sleeve              = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.SLEEVE)?.Value;
                    var itemStyleValue      = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.ITEMSTYLE)?.Value;
                    var color1              = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.COLOR1)?.Value;
                    var shippingSize        = styleFeatures.FirstOrDefault(f => f.FeatureId == StyleFeatureHelper.SHIPPING_SIZE)?.Value;
                    var isSmallShippingSize = shippingSize == "XS" || shippingSize == "S";

                    var searchTerms = style != null ? style.SearchTerms : null;
                    var isToddler   = items.All(i => SizeHelper.IsToddlers(i.StyleSize));
                    var description = style != null ? style.Description : null;
                    description = StringHelper.TrimTags(description);

                    var category = GrouponUtils.GetCategories(gender, itemStyleValue);

                    if (category == null || !category.Any())
                    {
                        _log.Info("No category info");
                        continue;
                    }
                    if (!style.MSRP.HasValue)
                    {
                        _log.Info("No MSRP");
                        //continue;
                    }

                    var packageSize = GrouponUtils.GetSizes(shippingSize);

                    var attributes = FillAttributesByCategory(category,
                                                              styleFeatures,
                                                              description,
                                                              style.Name,
                                                              item.Color,
                                                              styleItem.Size ?? item.Size);

                    if (attributes == null || !attributes.Any())
                    {
                        _log.Info("No attributes, category=" + category);
                        continue;
                    }

                    var model = new GrouponGoodLine()
                    {
                        CategoryID            = category,
                        VendorSKU             = item.SKU,
                        Title                 = GrouponUtils.PrepareText(StringHelper.Substring(style.Name, 80)),
                        Description           = GrouponUtils.PrepareText(StringHelper.GetFirstNotEmpty(description, style.Name)),
                        Manufacturer          = mainLicense,
                        ModelNumber           = style.StyleID,
                        Brand                 = mainLicense,
                        IsBundle              = "No",
                        ProductIdentifierType = "UPC",
                        ProductIdentifier     = item.Barcode,
                        VariationGroupingID   = StringHelper.GetFirstNotEmpty(parentItem.GroupId, parentItem.ASIN),

                        UnitPrice         = PriceHelper.RoundRoundToTwoPrecision(item.CurrentPrice).ToString(),
                        ShippingCost      = PriceHelper.RoundRoundToTwoPrecision(0).ToString(), //NOTE: Free
                        ReferencePrice    = style.MSRP.HasValue ? PriceHelper.RoundRoundToTwoPrecision(style.MSRP.Value).ToString() : "",
                        ReferencePriceURL = item.SourceMarketUrl,

                        ProductWeight         = (decimal)(item.Weight ?? 1.0),
                        ProductWeightUnit     = "Ounces",
                        ProductHeight         = packageSize[0],
                        ProductLength         = packageSize[1],
                        ProductWidth          = packageSize[2],
                        ProductDimensionsUnit = "Inches",
                        IsLTLShippingRequired = "No",
                        PackageWeight         = (decimal)(item.Weight ?? 1.0),
                        PackageWeightUnit     = "Ounces",
                        PackageHeight         = packageSize[0],
                        PackageLength         = packageSize[1],
                        PackageWidth          = packageSize[2],
                        PackageDimensionsUnit = "Inches",
                        CountryofOrigin       = "US",

                        Quantity = Math.Min(5, item.RealQuantity),

                        MainImage       = styleImages.Count > 0 ? styleImages[0]?.Image : "",
                        AlternateImage1 = styleImages.Count > 1 ? styleImages[1]?.Image : "",
                        AlternateImage2 = styleImages.Count > 2 ? styleImages[2]?.Image : "",
                        AlternateImage3 = styleImages.Count > 3 ? styleImages[3]?.Image : "",

                        Bullet1Description = GrouponUtils.PrepareText(StringHelper.Substring(StringHelper.TrimTags(style.BulletPoint1), 128)),
                        Bullet2Description = GrouponUtils.PrepareText(StringHelper.Substring(StringHelper.TrimTags(style.BulletPoint2), 128)),
                        Bullet3Description = GrouponUtils.PrepareText(StringHelper.Substring(StringHelper.TrimTags(style.BulletPoint3), 128)),
                        Bullet4Description = GrouponUtils.PrepareText(StringHelper.Substring(StringHelper.TrimTags(style.BulletPoint4), 128)),
                        Bullet5Description = GrouponUtils.PrepareText(StringHelper.Substring(StringHelper.TrimTags(style.BulletPoint5), 128)),

                        Attributes = attributes,
                    };

                    results.Add(model);
                }

                //Extract attributes
                var attributeNames = new Dictionary <string, int>();
                var lastIndex      = 1;
                foreach (var model in results)
                {
                    foreach (var attribte in model.Attributes)
                    {
                        if (!attributeNames.ContainsKey(attribte.Name))
                        {
                            attributeNames.Add(attribte.Name, lastIndex++);
                        }
                    }
                }

                foreach (var model in results)
                {
                    foreach (var attribute in model.Attributes)
                    {
                        var index = attributeNames[attribute.Name];
                        SetAttribute(model, index, attribute);
                    }
                }
            }

            return(results);
        }