private static void processKeywords(string text) { //comma delimited list of keywords - only "visible" keywords, never ad or seo keywords if (_firstRowForProduct) { var keywords = extractCsvList(text); if (_currentProduct.ProductKeywords == null) { _currentProduct.ProductKeywords = new Collection <ProductKeyword>(); } keywords.ForEach(keyword => { var keyObj = _currentProduct.ProductKeywords.FirstOrDefault(p => p.Value == keyword); if (keyObj == null) { //need to add it var newKeyword = new ProductKeyword { Value = keyword, TypeCode = "HIDD", ID = globalUniqueId-- }; _currentProduct.ProductKeywords.Add(newKeyword); } }); //now select any product keywords that are not in the sheet's list, and remove them var toRemove = _currentProduct.ProductKeywords.Where(p => !keywords.Contains(p.Value)).ToList(); toRemove.ForEach(r => _currentProduct.ProductKeywords.Remove(r)); } }
private static void processKeywords(string text) { //comma delimited list of keywords - only "visible" keywords, never ad or seo keywords if (_firstRowForProduct) { var keywords = extractCsvList(text); if (_currentProduct.ProductKeywords == null) { _currentProduct.ProductKeywords = new Collection<ProductKeyword>(); } keywords.ForEach(keyword => { var keyObj = _currentProduct.ProductKeywords.FirstOrDefault(p => p.Value == keyword); if (keyObj == null) { //need to add it var newKeyword = new ProductKeyword {Value = keyword, TypeCode = "HIDD", ID = globalUniqueId--}; _currentProduct.ProductKeywords.Add(newKeyword); } }); //now select any product keywords that are not in the sheet's list, and remove them var toRemove = _currentProduct.ProductKeywords.Where(p => !keywords.Contains(p.Value)).ToList(); toRemove.ForEach(r => _currentProduct.ProductKeywords.Remove(r)); } }