Example #1
0
 private int GetAttributeID(string name, Objects.DataAccess.UnitOfWork.IUnitOfWork unit)
 {
     if (AttributeMapping.Contains(name))
     {
         return(outList.FirstOrDefault(x => x.AttributeCode == name).AttributeID);
     }
     else
     {
         AttributeMapping.Add(name);
         SetupAttributes(unit, AttributeMapping.ToArray(), out outList, VendorID);
         return(outList.FirstOrDefault(x => x.AttributeCode == name).AttributeID);
     }
 }
Example #2
0
        private void ParseDocuments(Objects.DataAccess.UnitOfWork.IUnitOfWork unit, XDocument[] products, XDocument cont)
        {
            #region Xml Data

            //products = new XDocument[1];
            //products[0] = XDocument.Load(@"C:\Lenmar\test.xml");

            log.AuditInfo("Start parsing items");

            var itemContent = (from content in cont.Root.Elements("item")
                               let atts = content.Elements().Where(x => AttributeMapping.Contains(x.Name.LocalName))
                                          where content.Element("LenmarSKU") != null && content.Element("Description") != null && content.Element("Manufacturer") != null
                                          select new
            {
                LenmarSKU = content.Element("LenmarSKU").Value,
                ShortContentDescription = content.Element("Description").Value,
                GroupCode = content.Element("Manufacturer").Value,
                CostPrice = content.Element("BC_euro_cost") != null ? content.Element("BC_euro_cost").Value : "0",
                dynamic = atts
            }).ToList();
            XNamespace xName = "http://logictec.com/schemas/internaldocuments";


            var itemProducts = (from d in products
                                from itemproduct in d.Elements(xName + "Envelope").Elements("Messages").Elements(xName + "Price")
                                let c = itemContent.Where(x => x.LenmarSKU == itemproduct.Element("SupplierSku").Value).FirstOrDefault()
                                        select new
            {
                VendorBrandCode = itemproduct.Element("MfgName").Value,
                VendorName = itemproduct.Element("MfgName").Value,
                SupplierSKU = itemproduct.Element("SupplierSku").Value,
                CustomItemNr = itemproduct.Element("MfgSKU").Value,
                ShortDescription = itemproduct.Element("ProductName").Value,
                Price = itemproduct.Element("MSRP").Value,
                Status = itemproduct.Element("Active").Value,
                CostPrice = c != null ? c.CostPrice : itemproduct.Element("Price").Value,
                QuantityOnHand = itemproduct.Element("Inventory").Value,
                VendorProductGroupCode1 = itemproduct.Element("Category1").Value,
                VendorProductGroupCode2 = itemproduct.Element("Category2").Value,
                VendorProductGroupCode3 = itemproduct.Element("Category3").Value,
                VendorProductGroupCode4 = itemproduct.Element("Category4").Value,
                VendorProductGroupCode5 = itemproduct.Element("Category5").Value,
                Barcode = itemproduct.Element("UPCCode").Value,
                ShortContentDescription = c != null ? c.ShortContentDescription : string.Empty
            }).ToList();

            log.AuditInfo("Finished parsing items");
            #endregion


            SetupAttributes(unit, AttributeMapping.ToArray(), out attributes, VendorID);

            //Used for VendorImportAttributeValues
            var productAttributes = unit.Scope.Repository <ProductAttributeMetaData>().GetAll(c => c.VendorID == VendorID).ToList();
            attributeList = productAttributes.ToDictionary(x => x.AttributeCode, y => y.AttributeID);

            List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem> assortmentList = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem>();

            int counter = 0;
            int total   = itemProducts.Count();
            int totalNumberOfProductsToProcess = total;
            log.InfoFormat("Start processing {0} products", total);


            foreach (var product in itemProducts)
            {
                if (counter == 50)
                {
                    counter = 0;
                    log.InfoFormat("Still need to process {0} of {1}; {2} done;", totalNumberOfProductsToProcess, total, total - totalNumberOfProductsToProcess);
                }
                totalNumberOfProductsToProcess--;
                counter++;

                var assortment = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem
                {
                    #region BrandVendor
                    BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                    {
                        new VendorAssortmentBulk.VendorImportBrand()
                        {
                            VendorID        = VendorID,
                            VendorBrandCode = product.VendorBrandCode.Trim(),
                            ParentBrandCode = null,
                            Name            = product.VendorBrandCode.Trim()
                        }
                    },
                    #endregion

                    #region GeneralProductInfo
                    VendorProduct = new VendorAssortmentBulk.VendorProduct
                    {
                        VendorItemNumber = product.SupplierSKU.Trim(),  //EAN
                        CustomItemNumber = product.CustomItemNr.Trim(), //EAN
                        ShortDescription = product.ShortDescription.Length > 150
                                     ? product.ShortDescription.Substring(0, 150)
                                     : product.ShortDescription,
                        LongDescription             = "",
                        LineType                    = null,
                        LedgerClass                 = null,
                        ProductDesk                 = null,
                        ExtendedCatalog             = null,
                        VendorID                    = VendorID,
                        DefaultVendorID             = DefaultVendorID,
                        VendorBrandCode             = product.VendorBrandCode.Trim(),            //UITGEVER_ID
                        Barcode                     = product.Try(x => x.Barcode, string.Empty), //EAN
                        VendorProductGroupCode1     = string.IsNullOrEmpty(product.VendorProductGroupCode1) ? "Battery" : product.VendorProductGroupCode1,
                        VendorProductGroupCodeName1 = product.VendorName,
                        VendorProductGroupCode2     = !string.IsNullOrEmpty(product.VendorProductGroupCode2) ? product.VendorProductGroupCode2 : null,
                        VendorProductGroupCodeName2 = product.VendorName,
                        VendorProductGroupCode3     = !string.IsNullOrEmpty(product.VendorProductGroupCode3) ? product.VendorProductGroupCode3 : null,
                        VendorProductGroupCodeName3 = product.VendorName,
                        VendorProductGroupCode4     = !string.IsNullOrEmpty(product.VendorProductGroupCode4) ? product.VendorProductGroupCode4 : null,
                        VendorProductGroupCodeName4 = product.VendorName,
                        VendorProductGroupCode5     = !string.IsNullOrEmpty(product.VendorBrandCode) ? product.VendorBrandCode : null,
                        VendorProductGroupCodeName5 = product.VendorName
                    },
                    #endregion

                    #region RelatedProducts
                    RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>()
                    {
                    },
                    #endregion

                    #region Attributes

                    VendorImportAttributeValues = (from content in itemContent.Where(x => x.LenmarSKU == product.SupplierSKU)
                                                   from att in content.dynamic
                                                   let attributeID = attributeList.ContainsKey(att.Name.ToString()) ? attributeList[att.Name.ToString()] : -1
                                                                     let value = att.Value.ToString()
                                                                                 where !string.IsNullOrEmpty(value)
                                                                                 select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue
                    {
                        VendorID = VendorID,
                        DefaultVendorID = DefaultVendorID,
                        CustomItemNumber = product.CustomItemNr.Trim(),                    //EAN
                        AttributeID = attributeID,
                        Value = value,
                        LanguageID = "1",
                        AttributeCode = att.Name.ToString(),
                    }).ToList(),

                    #endregion

                    #region Prices
                    VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                    {
                        new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice()
                        {
                            VendorID         = VendorID,
                            DefaultVendorID  = DefaultVendorID,
                            CustomItemNumber = product.CustomItemNr.Trim(),                                                             //EAN
                            Price            = (Decimal.Parse(product.Price) / 119).ToString("0.00", CultureInfo.InvariantCulture),
                            CostPrice        = (Decimal.Parse(product.CostPrice) / 100).ToString("0.00", CultureInfo.InvariantCulture), //NETTOPRIJS
                            TaxRate          = "19",
                            MinimumQuantity  = 0,
                            CommercialStatus = product.Status
                        }
                    },
                    #endregion

                    #region Stock
                    VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>()
                    {
                        new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock()
                        {
                            VendorID         = VendorID,
                            DefaultVendorID  = DefaultVendorID,
                            CustomItemNumber = product.CustomItemNr.Trim(),     //EAN
                            QuantityOnHand   = int.Parse(product.QuantityOnHand),
                            StockType        = "Assortment",
                            StockStatus      = product.Status
                        }
                    },
                    #endregion

                    #region Descriptions
                    VendorProductDescriptions = new List <VendorAssortmentBulk.VendorProductDescription>()
                    {
                        new VendorAssortmentBulk.VendorProductDescription()
                        {
                            VendorID                = VendorID,
                            LanguageID              = languageID,
                            DefaultVendorID         = VendorID,
                            CustomItemNumber        = product.CustomItemNr.Trim(), //EAN
                            LongContentDescription  = string.Empty,
                            ShortContentDescription = product.ShortContentDescription != string.Empty ? product.ShortContentDescription.Length > 1000
                                     ?product.ShortContentDescription.Substring(0, 1000)
                                      : product.ShortContentDescription : product.ShortDescription,
                            ProductName = product.ShortDescription
                        }
                    }
                    #endregion
                };

                // assortment will be added to the list defined outside of this loop
                assortmentList.Add(assortment);
            }

            // Creates a new instance of VendorAssortmentBulk(Passes in the AssortmentList defined above, vendorID and DefaultVendorID)
            using (var vendorAssortmentBulk = new VendorAssortmentBulk(assortmentList, VendorID, DefaultVendorID))
            {
                vendorAssortmentBulk.Init(unit.Context);
                vendorAssortmentBulk.Sync(unit.Context);
            }
        }
        protected override List <Objects.Models.Vendors.VendorAssortment> GetVendorProducts(Objects.DataAccess.UnitOfWork.IUnitOfWork unit, string imageName)
        {
            Int32[] _vendorIDs = GetConfiguration().AppSettings.Settings["VendorIDs"].Value.Split(',').Select(x => Convert.ToInt32(x)).ToArray();

            String[] filearray = imageName.Split('_');

            String CustomItemNumber = filearray[0];
            String ColorCode        = filearray[1].Replace('-', '/');

            var vendorAssortment = new List <Objects.Models.Vendors.VendorAssortment>();

            foreach (var vendorID in _vendorIDs)
            {
                var assortment = unit.Scope.Repository <VendorAssortment>().GetAll(x => x.VendorID == vendorID && (x.CustomItemNumber.Trim() == CustomItemNumber ||
                                                                                                                   x.CustomItemNumber.Trim() == CustomItemNumber + " " + ColorCode ||
                                                                                                                   x.CustomItemNumber.Trim().StartsWith(CustomItemNumber + " " + ColorCode + " "))).ToList();

                vendorAssortment.AddRange(assortment);
            }

            return(vendorAssortment);
        }
        private void DoProcess(List <TrdPartyProductModel> data, List <Attributes> atts, Objects.DataAccess.UnitOfWork.IUnitOfWork unit)
        {
            var config = GetConfiguration();

            var vendorID_NL = vendors.First(x => x.Value == "NL").Key;
            var vendorID_BE = vendors.First(x => x.Value == "BE").Key;

            var repoBrandVendor = unit.Scope.Repository <BrandVendor>();

            var prodRepo = unit.Scope.Repository <Product>().Include(c => c.ProductMedias, c => c.ProductBarcodes, c => c.ProductDescriptions);
            var productAttributeGroups = unit.Scope.Repository <ProductAttributeGroupMetaData>().GetAll(g => g.VendorID == vendorID_NL || g.VendorID == vendorID_BE).ToList();
            var repoAssortment         = unit.Scope.Repository <VendorAssortment>().Include(c => c.VendorPrices);
            var stockRepo                = unit.Scope.Repository <VendorStock>();
            var repoAttributeGroup       = unit.Scope.Repository <ProductAttributeGroupMetaData>();
            var repoAttributeGroupName   = unit.Scope.Repository <ProductAttributeGroupName>();
            var repoAttributeValue       = unit.Scope.Repository <ProductAttributeValue>();
            var repotAttributeName       = unit.Scope.Repository <ProductAttributeName>();
            var repoAttribute            = unit.Scope.Repository <ProductAttributeMetaData>().Include(c => c.ProductAttributeNames, c => c.ProductAttributeValues);
            var repoVendor               = unit.Scope.Repository <ProductGroupVendor>();
            var prodDescriptionRepo      = unit.Scope.Repository <ProductDescription>();
            var priceRepo                = unit.Scope.Repository <VendorPrice>();
            var productGroupLanguageRepo = unit.Scope.Repository <ProductGroupLanguage>();
            var productGroupMappingRepo  = unit.Scope.Repository <ProductGroupMapping>();

            //var products = prodRepo.GetAll(x => x.SourceVendorID == VendorID).ToList();
            var vendorassortments = repoAssortment.GetAll(x => x.VendorID == vendorID_NL || x.VendorID == vendorID_BE).ToList();
            var productAttributes = repoAttribute.GetAll(g => g.VendorID == vendorID_NL || g.VendorID == vendorID_BE).ToList();

            var productGroupVendorRecords = repoVendor.GetAll(pc => pc.VendorID == vendorID_NL || pc.VendorID == vendorID_BE).ToList();
            var brands              = repoBrandVendor.GetAll(bv => bv.VendorID == vendorID_NL || bv.VendorID == vendorID_BE).ToList();
            var brandEnts           = unit.Scope.Repository <Brand>().GetAll();
            var products            = prodRepo.GetAll(x => x.SourceVendorID == vendorID_NL || x.SourceVendorID == vendorID_BE).ToList();
            var vendorStock         = stockRepo.GetAll(x => x.VendorID == vendorID_NL || x.VendorID == vendorID_BE).ToList();
            var productDescriptions = prodDescriptionRepo.GetAll().ToList();

            var productGroupLanguages = productGroupLanguageRepo.GetAll().ToList();
            var prodAttributeGroups   = repoAttributeGroup.GetAll(g => g.VendorID == vendorID_NL || g.VendorID == vendorID_BE).ToList();
            var productGroupMapping   = productGroupMappingRepo.GetAll(x => x.ConnectorID == 2).ToList();

            int counter = 0;
            int total   = data.Count();
            int totalNumberOfProductsToProcess = total;

            log.InfoFormat("Start import {0} products", total);
            bool firstVendor = true;

            foreach (var VendorID in vendors.Keys)
            {
                ProductStatusVendorMapper mapper = new ProductStatusVendorMapper(unit.Scope.Repository <VendorProductStatus>(), VendorID);
                var vendor = unit.Scope.Repository <Vendor>().GetSingle(x => x.VendorID == VendorID);

                foreach (var product in data)
                {
                    if (string.IsNullOrEmpty(product.Artnr))
                    {
                        continue;
                    }
                    try
                    {
                        if (counter == 100)
                        {
                            counter = 0;
                            log.InfoFormat("Still need to process {0} of {1}; {2} done for {3};", totalNumberOfProductsToProcess, total, total - totalNumberOfProductsToProcess, VendorID);
                        }

                        totalNumberOfProductsToProcess--;
                        counter++;

                        var brand   = brandEnts.FirstOrDefault(c => c.Name.ToLower() == product.BrandName.Trim().ToLower());
                        int brandID = 0;

                        if (brand == null)
                        {
                            var vbrand = brands.FirstOrDefault(vb => vb.VendorBrandCode.Trim() == product.BrandName.Trim());

                            if (vbrand == null)
                            {
                                vbrand = new BrandVendor
                                {
                                    VendorID        = VendorID,
                                    VendorBrandCode = product.BrandName.Trim(),
                                    BrandID         = unmappedID,
                                    Name            = product.BrandName.Trim()
                                };

                                brands.Add(vbrand);

                                repoBrandVendor.Add(vbrand);
                            }
                            brandID = vbrand.BrandID;
                        }
                        else
                        {
                            brandID = brand.BrandID;
                        }

                        var item = products.FirstOrDefault(p => p.VendorItemNumber.Trim() == product.Artnr.Trim() && p.BrandID == brandID);
                        if (item == null)
                        {
                            item = new Product
                            {
                                VendorItemNumber = product.Artnr.Trim(),
                                BrandID          = brandID,
                                SourceVendorID   = VendorID
                            };
                            prodRepo.Add(item);
                            products.Add(item);
                            unit.Save();
                        }

                        if (firstVendor)
                        {
                            var productDescription = productDescriptions.FirstOrDefault(pd => pd.Product.VendorItemNumber == item.VendorItemNumber && pd.LanguageID == 1 && (pd.VendorID == vendor.VendorID || (vendor.ParentVendorID.HasValue && pd.VendorID == vendor.VendorID)));

                            if (productDescription == null)
                            {
                                //create ProductDescription
                                productDescription = new ProductDescription
                                {
                                    Product    = item,
                                    LanguageID = languageID,
                                    VendorID   = VendorID,
                                };

                                prodDescriptionRepo.Add(productDescription);
                                productDescriptions.Add(productDescription);
                            }

                            if (string.IsNullOrEmpty(productDescription.ProductName))
                            {
                                productDescription.ProductName = product.Product;
                                productDescription.ModelName   = product.Product;
                            }

                            if (!string.IsNullOrEmpty(product.ShortDescription))
                            {
                                productDescription.ShortContentDescription = product.ShortDescription.Cap(1000);
                            }

                            if (string.IsNullOrEmpty(productDescription.LongContentDescription))
                            {
                                productDescription.LongContentDescription = product.LongDescription;
                            }

                            if (string.IsNullOrEmpty(productDescription.LongSummaryDescription))
                            {
                                productDescription.LongSummaryDescription = product.LongDescription;
                            }
                        }

                        var assortment = vendorassortments.FirstOrDefault(x => x.Product.VendorItemNumber == item.VendorItemNumber.Trim() && x.VendorID == VendorID);
                        if (assortment == null)
                        {
                            assortment = new VendorAssortment
                            {
                                VendorID         = VendorID,
                                Product          = item,
                                ShortDescription = product.Try(c => c.ShortDescription.Cap(1000), string.Empty),//.ShortDescription // .Length > 150 ? product.ShortDescription.Substring(0, 150) : product.ShortDescription,
                                CustomItemNumber = product.Artnr.Trim(),
                                IsActive         = true,
                                LongDescription  = product.LongDescription
                            };
                            vendorassortments.Add(assortment);
                            repoAssortment.Add(assortment);
                        }

                        var productGroups = new string[4];
                        productGroups[0] = product.BrandName;
                        productGroups[1] = product.Chapter;
                        productGroups[2] = product.Category;
                        productGroups[3] = product.Subcategory;

                        var pgvs = assortment.ProductGroupVendors != null?assortment.ProductGroupVendors.ToList() : new List <ProductGroupVendor>();

                        ProductGroupMapping parentpgm = null;

                        for (int i = 0; i < productGroups.Length; i++)
                        {
                            var groupCode = productGroups[i];

                            if (string.IsNullOrEmpty(groupCode))
                            {
                                continue;
                            }

                            var productGroup = productGroupLanguages.FirstOrDefault(x => x.Name == groupCode.Trim());
                            if (productGroup == null)
                            {
                                var pg = new Concentrator.Objects.Models.Products.ProductGroup()
                                {
                                    Score = 0
                                };

                                unit.Scope.Repository <Concentrator.Objects.Models.Products.ProductGroup>().Add(pg);

                                productGroup = new ProductGroupLanguage()
                                {
                                    ProductGroup = pg,
                                    LanguageID   = 1,
                                    Name         = groupCode.Trim()
                                };

                                productGroupLanguages.Add(productGroup);
                                productGroupLanguageRepo.Add(productGroup);
                                unit.Save();
                            }

                            //var productGroupVendor = productGroupVendorRecords.Where(pg => pg.GetType().GetProperty(string.Format("VendorProductGroupCode{0}", i + 1)).GetValue(pg, null) != null
                            //        && pg.GetType().GetProperty(string.Format("VendorProductGroupCode{0}", i + 1)).GetValue(pg, null).ToString() == groupCode.Trim()).FirstOrDefault();

                            var productGroupVendor = productGroupVendorRecords.FirstOrDefault(x => x.ProductGroupID == productGroup.ProductGroupID);

                            if (productGroupVendor == null)
                            {
                                productGroupVendor = new ProductGroupVendor
                                {
                                    ProductGroupID = productGroup.ProductGroupID,
                                    VendorID       = VendorID,
                                    VendorName     = groupCode.Trim(),
                                };

                                productGroupVendor.GetType().GetProperty(string.Format("VendorProductGroupCode{0}", i + 1)).SetValue(productGroupVendor, groupCode.Trim().Cap(50), null);

                                repoVendor.Add(productGroupVendor);
                                productGroupVendorRecords.Add(productGroupVendor);
                            }

                            if (productGroupVendor.VendorAssortments == null)
                            {
                                productGroupVendor.VendorAssortments = new List <VendorAssortment>();
                            }

                            var assortmentRelation = productGroupVendor.VendorAssortments.Count == 0 ? null : productGroupVendor.VendorAssortments.Where(c => c.Product != null && c.Product.VendorItemNumber == item.VendorItemNumber.Trim() && c.VendorID == VendorID).FirstOrDefault();
                            if (assortmentRelation == null)
                            {
                                productGroupVendor.VendorAssortments.Add(assortment);
                            }
                            else
                            {
                                pgvs.Remove(productGroupVendor);
                            }

                            if (productGroupVendor.ProductGroupID > 0)
                            {
                                ProductGroupMapping pgm = null;

                                if (parentpgm != null)
                                {
                                    pgm = productGroupMapping.FirstOrDefault(x => x.ProductGroupID == productGroupVendor.ProductGroupID && x.ParentProductGroupMappingID == parentpgm.ProductGroupMappingID);
                                }
                                else
                                {
                                    pgm = productGroupMapping.FirstOrDefault(x => x.ProductGroupID == productGroupVendor.ProductGroupID);
                                }

                                if (pgm == null)
                                {
                                    pgm = new ProductGroupMapping()
                                    {
                                        ConnectorID         = 2,
                                        ProductGroupID      = productGroupVendor.ProductGroupID,
                                        FlattenHierarchy    = false,
                                        FilterByParentGroup = parentpgm != null ? true : false,
                                        Depth = i,
                                        Score = 0
                                    };

                                    if (parentpgm != null)
                                    {
                                        pgm.ParentProductGroupMappingID = parentpgm.ProductGroupMappingID;
                                    }

                                    unit.Scope.Repository <ProductGroupMapping>().Add(pgm);
                                    unit.Save();
                                    productGroupMapping.Add(pgm);
                                }
                                parentpgm = pgm;
                            }
                        }

                        pgvs.ForEach(pg =>
                        {
                            productGroupVendorRecords.Remove(pg);
                        });

                        if (firstVendor)
                        {
                            if (!string.IsNullOrEmpty(product.PriceGroup))
                            {
                                atts.Add(new Attributes()
                                {
                                    AttArtnr = product.Artnr.Trim(),
                                    Feature  = "PriceGroup",
                                    Value    = product.PriceGroup
                                });
                            }

                            if (!string.IsNullOrEmpty(product.Features))
                            {
                                atts.Add(new Attributes()
                                {
                                    AttArtnr = product.Artnr.Trim(),
                                    Feature  = "Features",
                                    Value    = product.Features
                                });
                            }

                            if (!string.IsNullOrEmpty(product.NEW))
                            {
                                atts.Add(new Attributes()
                                {
                                    AttArtnr = product.Artnr.Trim(),
                                    Feature  = "New",
                                    Value    = product.NEW
                                });
                            }

                            var attributes = atts.Where(x => x.AttArtnr != null && (x.AttArtnr.Trim() == product.Artnr.Trim())).ToList();

                            if (attributes != null && attributes.Count > 0)
                            {
                                foreach (var att in attributes)
                                {
                                    string AttributeCode        = "General",
                                             AttributeGroupCode = att.Feature,
                                             AttributeValue     = att.Value;

                                    if (!string.IsNullOrEmpty(AttributeGroupCode) && !string.IsNullOrEmpty(AttributeValue))
                                    {
                                        var productAttributeMetadata = productAttributes.FirstOrDefault(c => c.ProductAttributeNames.Any(l => l.Name == AttributeGroupCode) && c.VendorID == VendorID);
                                        if (productAttributeMetadata == null)
                                        {
                                            productAttributeMetadata = new ProductAttributeMetaData
                                            {
                                                AttributeCode = att.Feature,
                                                Index         = 0,
                                                IsVisible     = true,
                                                NeedsUpdate   = true,
                                                VendorID      = VendorID,
                                                IsSearchable  = false
                                            };
                                            productAttributes.Add(productAttributeMetadata);
                                            repoAttribute.Add(productAttributeMetadata);
                                        }

                                        var attributeGroup = productAttributeMetadata.ProductAttributeGroupMetaData;
                                        if (attributeGroup == null)
                                        {
                                            attributeGroup = new ProductAttributeGroupMetaData
                                            {
                                                Index     = 0,
                                                GroupCode = "TechnicalData",
                                                VendorID  = VendorID
                                            };
                                            repoAttributeGroup.Add(attributeGroup);
                                            productAttributeMetadata.ProductAttributeGroupMetaData = attributeGroup;
                                        }
                                        productAttributeMetadata.ProductAttributeGroupID = attributeGroup.ProductAttributeGroupID;

                                        var attributeGroupName = attributeGroup.ProductAttributeGroupNames.FirstOrDefault(c => c.LanguageID == 1);
                                        if (attributeGroupName == null)
                                        {
                                            attributeGroupName = new ProductAttributeGroupName
                                            {
                                                Name       = AttributeCode,
                                                LanguageID = languageID,
                                                ProductAttributeGroupMetaData = attributeGroup
                                            };
                                            repoAttributeGroupName.Add(attributeGroupName);
                                            attributeGroup.ProductAttributeGroupNames.Add(attributeGroupName);
                                        }



                                        var attributeName = productAttributeMetadata.ProductAttributeNames.FirstOrDefault(c => c.LanguageID == 1);
                                        if (attributeName == null)
                                        {
                                            attributeName = new ProductAttributeName
                                            {
                                                ProductAttributeMetaData = productAttributeMetadata,
                                                LanguageID = 1,
                                                Name       = AttributeGroupCode
                                            };
                                            repotAttributeName.Add(attributeName);
                                            productAttributeMetadata.ProductAttributeNames.Add(attributeName);
                                        }

                                        var attributeValue = productAttributeMetadata.ProductAttributeValues.FirstOrDefault(c => c.Value == AttributeValue && c.ProductID == item.ProductID);
                                        if (attributeValue == null && !string.IsNullOrEmpty(AttributeValue))
                                        {
                                            attributeValue = new ProductAttributeValue
                                            {
                                                Value = AttributeValue,
                                                ProductAttributeMetaData = productAttributeMetadata,
                                                LanguageID = 1,
                                                Product    = item
                                            };
                                            productAttributeMetadata.ProductAttributeValues.Add(attributeValue);
                                            repoAttributeValue.Add(attributeValue);
                                        }
                                    }
                                }
                            }
                        }

                        var stock = vendorStock.FirstOrDefault(c => c.Product.VendorItemNumber == item.VendorItemNumber.Trim() && c.VendorID == VendorID);

                        if (stock == null)
                        {
                            stock = new VendorStock
                            {
                                Product           = item,
                                QuantityOnHand    = 0,
                                VendorID          = VendorID,
                                VendorStockTypeID = 1
                            };
                            vendorStock.Add(stock);
                            stockRepo.Add(stock);
                        }



                        if (assortment.VendorPrices == null)
                        {
                            assortment.VendorPrices = new List <VendorPrice>();
                        }


                        var vendorPrice = assortment.VendorPrices.FirstOrDefault();
                        //create vendorPrice with vendorAssortmentID
                        if (vendorPrice == null)
                        {
                            vendorPrice = new VendorPrice
                            {
                                VendorAssortment = assortment,
                                CommercialStatus = "S",
                                MinimumQuantity  = 0
                            };
                            priceRepo.Add(vendorPrice);
                            assortment.VendorPrices.Add(vendorPrice);
                        }

                        decimal taxRate   = 19;
                        decimal price     = 0;
                        decimal costPrice = 0;

                        switch (vendors[VendorID])
                        {
                        case "NL":
                            taxRate = 19;
                            Decimal.TryParse(product.VATExclNL, out costPrice);
                            Decimal.TryParse(product.NLincl, out price);
                            break;

                        case "BE":
                            taxRate = 21;
                            Decimal.TryParse(product.VATExclBE, out costPrice);
                            Decimal.TryParse(product.BEincl, out price);
                            break;
                        }

                        vendorPrice.Price     = price;
                        vendorPrice.CostPrice = costPrice;
                        vendorPrice.TaxRate   = taxRate;

                        if (product.Image != null)
                        {
                            if (item.ProductMedias == null)
                            {
                                item.ProductMedias = new List <ProductMedia>();
                            }
                            if (!item.ProductMedias.Any(pi => pi.VendorID == VendorID && pi.MediaUrl == product.Image))
                            {
                                unit.Scope.Repository <ProductMedia>().Add(new ProductMedia
                                {
                                    VendorID = VendorID,
                                    MediaUrl = product.Image,
                                    TypeID   = 1, // image
                                    Product  = item,
                                    Sequence = 0
                                });
                            }
                        }


                        if (product.EAN != null || product.Barcode != null)
                        {
                            if (item.ProductBarcodes == null)
                            {
                                item.ProductBarcodes = new List <ProductBarcode>();
                            }
                            if (!item.ProductBarcodes.Any(pb => pb.Barcode.Trim() == product.EAN.Trim()))
                            {
                                unit.Scope.Repository <ProductBarcode>().Add(new ProductBarcode
                                {
                                    Product     = item,
                                    Barcode     = product.EAN != null ? product.EAN : product.Barcode != null ? product.Barcode : "",
                                    BarcodeType = (int)BarcodeTypes.Default,
                                    VendorID    = VendorID
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.AuditError("Error import products for Sennheiser 3rdParty", ex);
                    }
                }
                firstVendor = false;
            }
        }
 protected override string GetWatchDirectory(Objects.DataAccess.UnitOfWork.IUnitOfWork unit)
 {
     return(unit.Scope.Repository <VendorSetting>().GetSingle(c => c.VendorID == VendorID && c.SettingKey == "ImageDirectory").Value);
 }