private void ProcessCsv(CsvParser parser) { using (var unit = GetUnitOfWork()) { RelatedProductTypes relatedProductTypes = new RelatedProductTypes(unit.Scope.Repository <RelatedProductType>()); var relatedProductType = relatedProductTypes.SyncRelatedProductTypes("CompatibleProducts"); //there are products with repeating vendoritemnumbers List <string> vendorItemNumbers = unit.Scope.Repository <Product>().GetAll(p => p.SourceVendorID == VendorID).Select(c => c.VendorItemNumber).ToList(); var vendor = unit.Scope.Repository <Vendor>().GetSingle(x => x.VendorID == VendorID); int couterProduct = 0; int logCount = 0; var importedproducts = parser.ToList(); int totalProducts = importedproducts.Count(); ProductStatusVendorMapper mapper = new ProductStatusVendorMapper(unit.Scope.Repository <VendorProductStatus>(), VendorID); List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem> assortmentList = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem>(); //Used for VendorImportAttributeValues var productAttributes = unit.Scope.Repository <ProductAttributeMetaData>().GetAll(c => c.VendorID == VendorID).ToList(); var attributeList = productAttributes.ToDictionary(x => x.AttributeCode, y => y.AttributeID); foreach (Dictionary <string, string> record in importedproducts) { couterProduct++; logCount++; if (logCount == 250) { log.DebugFormat("Products Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, vendor.Name); logCount = 0; } int concentratorStatusID = -1; DateTime backorderDate = DateTime.Now; if (!string.IsNullOrEmpty(record.Get(TechDataColumnDefs.BackorderDate.ToString())) && DateTime.TryParseExact(record.Get(TechDataColumnDefs.BackorderDate.ToString()), "dd/MM/yyyy", null, DateTimeStyles.None, out backorderDate) && DateTime.Compare(backorderDate, DateTime.Now) > 0) { concentratorStatusID = mapper.SyncVendorStatus("BackOrder", -1); } else { concentratorStatusID = mapper.SyncVendorStatus("InStock", -1); } string vendorItemNumber = record.Get(TechDataColumnDefs.VendorItemNumber.ToString()).Trim(); //if already an item with this vendor item number exists --> do nothing if (vendorItemNumbers.Contains(vendorItemNumber.Trim())) { continue; } Decimal price = decimal.Parse(record.Get(TechDataColumnDefs.Price.ToString())); string customItemNumber = record.Get(TechDataColumnDefs.CustomItemNumber.ToString()).Trim(); string productGroupCode = record.Get(TechDataColumnDefs.GrandChildVendorProductGroupCode.ToString()); string parentProductGroupCode = record.Get(TechDataColumnDefs.ChildVendorProductGroupCode.ToString()); string grandParentProductGroupCode = record.Get(TechDataColumnDefs.ParentVendorProductGroupCode.ToString()); var assortment = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem { #region BrandVendor BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>() { new VendorAssortmentBulk.VendorImportBrand() { VendorID = VendorID, VendorBrandCode = record.Get(TechDataColumnDefs.Brand.ToString()).Trim().ToLower(), ParentBrandCode = null, Name = record.Get(TechDataColumnDefs.Brand.ToString()).Trim().ToLower(), } }, #endregion #region GeneralProductInfo VendorProduct = new VendorAssortmentBulk.VendorProduct { VendorItemNumber = vendorItemNumber, CustomItemNumber = customItemNumber, ShortDescription = record.Get(TechDataColumnDefs.Description.ToString()), LongDescription = record.Get(TechDataColumnDefs.Description.ToString()), LineType = null, LedgerClass = null, ProductDesk = null, ExtendedCatalog = null, VendorID = VendorID, DefaultVendorID = DefaultVendorID, VendorBrandCode = record.Get(TechDataColumnDefs.Brand.ToString()).Trim().ToLower(), Barcode = record.Get(TechDataColumnDefs.EanCode.ToString()), VendorProductGroupCode1 = grandParentProductGroupCode, VendorProductGroupCodeName1 = null, VendorProductGroupCode2 = parentProductGroupCode, VendorProductGroupCodeName2 = null, VendorProductGroupCode3 = productGroupCode, VendorProductGroupCodeName3 = null }, #endregion #region RelatedProducts RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>() { new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportRelatedProduct { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = customItemNumber, RelatedProductType = relatedProductType.Type, RelatedCustomItemNumber = vendorItemNumber } }, #endregion #region Attributes VendorImportAttributeValues = new List <VendorAssortmentBulk.VendorImportAttributeValue>(), //VendorImportAttributeValues = (from attr in enumValList // let prop = record.Equals(attr) // let attributeID = attributeList.ContainsKey(attr) ? attributeList[attr] : 2 //TODO set as -1 // let value = prop.ToString() // where !string.IsNullOrEmpty(value) // select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue // { // VendorID = VendorID, // DefaultVendorID = DefaultVendorID, // CustomItemNumber = customItemNumber, // AttributeID = attributeID, // Value = value, // LanguageID = "1", // AttributeCode = attr, // }).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 = customItemNumber, Price = price.ToString("0.00", CultureInfo.InvariantCulture), CostPrice = price.ToString("0.00", CultureInfo.InvariantCulture), TaxRate = "19", MinimumQuantity = 0, CommercialStatus = "SR" } }, #endregion #region Stock VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>() { new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock() { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = customItemNumber, QuantityOnHand = 0, StockType = "Assortment", StockStatus = "S" } }, #endregion }; assortmentList.Add(assortment); } using (var vendorAssortmentBulk = new VendorAssortmentBulk(assortmentList, VendorID, VendorID)) { vendorAssortmentBulk.Init(unit.Context); vendorAssortmentBulk.Sync(unit.Context); } } }
private void SyncRelatedProducts(Dictionary <string, ProductIdentifier> relations) { try { using (var unit = GetUnitOfWork()) { var repoProduct = unit.Scope.Repository <Product>(); var repoAssortment = unit.Scope.Repository <VendorAssortment>(); var relProductRepository = unit.Scope.Repository <RelatedProduct>().Include(c => c.RelatedProductType); RelatedProductTypes relatedProductTypes = new RelatedProductTypes(unit.Scope.Repository <RelatedProductType>()); var relatedProductType = relatedProductTypes.SyncRelatedProductTypes("CompatibleProducts"); foreach (var compatibility in relations) { var cp = compatibility.Value; var sourceProduct = repoProduct.GetSingle(c => c.VendorItemNumber == compatibility.Key); if (sourceProduct != null) { int sourceProdID = sourceProduct.ProductID; foreach (string pi in compatibility.Value.compatibleProducts) { #region Related Products var relatedProductID = repoAssortment.GetSingle(va => va.CustomItemNumber == pi && va.VendorID == VendorID).Try <VendorAssortment, int?>(c => c.ProductID, null); if (relatedProductID.HasValue) { RelatedProduct relProd = relProductRepository.GetSingle(rp => rp.ProductID == sourceProdID && rp.RelatedProductID == relatedProductID.Value && rp.VendorID == VendorID && rp.RelatedProductType.RelatedProductTypeID == relatedProductType.RelatedProductTypeID); if (relProd == null) { relProd = new RelatedProduct { ProductID = sourceProdID, RelatedProductID = relatedProductID.Value, VendorID = VendorID, RelatedProductType = relatedProductType }; relProductRepository.Add(relProd); } } #endregion } } } using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.FromMinutes(3))) { unit.Save(); ts.Complete(); } } } catch (Exception e) { log.AuditError("Import of related products failed", e); } }
protected void ProcessProductsTable(DataTable table, int vendorBrandID, IEnumerable <ProductAttributeMetaData> productAttributes, ProductGroupSyncer syncer, ProductStatusVendorMapper mapper, Dictionary <int, VendorAssortment> inactiveAss) { var products = (from r in table.Rows.Cast <DataRow>() where !String.IsNullOrEmpty(r.Field <string>("EANNumber")) group r by r.Field <string>("EANNumber") into grp let r = grp.First() select new { ProductID = r.Field <string>("ProductCode"), EAN = r.Field <string>("EANNumber"), EAN_Alt = r.Field <string>("EANNumberAlternative"), Description = r.Field <string>("ProductName"), TagLine = r.Field <string>("TagLine"), Title = r.Field <string>("Title"), ProductionYear = r.Field <int?>("ProductionYear"), RunningTime = r.Field <int?>("RunningTime"), CountryName = r.Field <string>("CountryName"), UsrReleaseDate = r.Field <string>("UsrReleaseDate"), ProductStatusID = r.Field <long?>("ProductStatusID"), ProductStatus = r.Field <string>("ProductStatus").Trim(), SalesPrice = r.Field <decimal?>("SalesPrice"), RetailPrice = ((r.Field <decimal?>("RetailPrice") ?? 0) / (decimal)1.19), ListRetailPrice = r.Field <decimal?>("ListRetailPrice"), ListSalesPrice = r.Field <decimal?>("ListSalesPrice"), InStock = r.Field <int?>("InStock"), GenreID = r.Field <long?>("GenreID"), GenreName = r.Field <string>("GenreName"), ProductGroupCode = r.Field <string>("ProductGroupCode"), ProductGroup = r.Field <string>("ProductGroup"), SubProductGroupCode = r.Field <string>("SubProductGroupCode"), SubProductGroup = r.Field <string>("SubProductGroup"), SubGenreID = r.Field <long?>("SubGenreID"), SubGenreName = r.Field <string>("SubGenreName"), RatingAge = r.Field <string>("RatingAge"), MediaType = r.Field <string>("MediaType"), MediaTypeID = r.Field <long?>("MediaTypeID"), Artist = r.Field <string>("Artist"), MediaDescription = r.Field <string>("MediaDescription") }).ToList(); using (IUnitOfWork unit = GetUnitOfWork()) { //DataLoadOptions options = new DataLoadOptions(); //options.LoadWith<ProductGroupVendor>(x => x.VendorProductGroupAssortments); //options.LoadWith<VendorAssortment>(x => x.VendorPrice); //options.LoadWith<Product>(x => x.ProductBarcodes); //ctx.LoadOptions = options; List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem> assortmentList = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem>(); RelatedProductTypes relatedProductTypes = new RelatedProductTypes(unit.Scope.Repository <RelatedProductType>()); var relatedProductType = relatedProductTypes.SyncRelatedProductTypes("CompatibleProducts"); var productGroupVendorRepo = unit.Scope.Repository <ProductGroupVendor>().Include(c => c.VendorAssortments); var assortmentRepo = unit.Scope.Repository <VendorAssortment>().Include(c => c.VendorPrices); var stockRepo = unit.Scope.Repository <VendorStock>(); var productRepo = unit.Scope.Repository <Product>().Include(c => c.ProductBarcodes); var priceRepo = unit.Scope.Repository <VendorPrice>(); var productGroupVendorRecords = productGroupVendorRepo.GetAll(c => c.VendorID == VendorID).ToList(); int step = 1000; int todo = products.Count(); int done = 0; var languages = new[] { (int)LanguageTypes.English, (int)LanguageTypes.Netherlands }; var vendorAssortment = assortmentRepo.GetAll(x => x.VendorID == VendorID).ToDictionary(x => x.ProductID, y => y); var attributeList = productAttributes.ToDictionary(x => x.AttributeCode, y => y.AttributeID); var vendorStock = stockRepo.GetAll(x => x.VendorID == VendorID).ToDictionary(x => x.ProductID, y => y); var prodType = products.First().GetType(); var currentProductGroupVendors = productGroupVendorRepo.GetAll(v => v.VendorID == VendorID).ToList(); log.InfoFormat(todo + " products to be processed"); while (done < todo) { log.DebugFormat("{0} products to be processed", todo - done); var toProcess = products.OrderByDescending(x => x.UsrReleaseDate).Skip(done).Take(step); foreach (var product in toProcess) { try { if (product.ProductGroupCode != "GAMES" && product.ProductGroupCode != "HARDWARE") { continue; } //#if DEBUG // if (product.EAN != "8714025503775") // continue; //#endif //log.DebugFormat("{0} products to be processed in batch", toProcess.Count()); var assortment = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem { #region BrandVendor BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>() { new VendorAssortmentBulk.VendorImportBrand() { VendorID = VendorID, VendorBrandCode = BrandVendorCode, ParentBrandCode = null, Name = product.GenreName } }, #endregion #region GeneralProductInfo VendorProduct = new VendorAssortmentBulk.VendorProduct { VendorItemNumber = product.EAN, CustomItemNumber = product.ProductID, ShortDescription = product.Description.Length > 150 ? product.Description.Substring(0, 150) : product.Description, LongDescription = product.Description, LineType = "S", LedgerClass = null, ProductDesk = null, ExtendedCatalog = null, VendorID = VendorID, DefaultVendorID = DefaultVendorID, VendorBrandCode = BrandVendorCode, Barcode = product.EAN, VendorProductGroupCode1 = product.ProductGroupCode, VendorProductGroupCodeName1 = product.ProductGroup, VendorProductGroupCode2 = product.SubProductGroupCode, VendorProductGroupCodeName2 = product.SubProductGroup, VendorProductGroupCode3 = product.GenreName //VendorProductGroupCodeName3 = product.SubProductGroup }, #endregion #region RelatedProducts RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>() { new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportRelatedProduct { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = product.ProductID, RelatedProductType = relatedProductType.Type, RelatedCustomItemNumber = product.EAN } }, #endregion #region Attributes VendorImportAttributeValues = (from attr in AttributeMapping let prop = product.Equals(attr)//d.Field<object>(attr) let attributeID = attributeList.ContainsKey(attr) ? attributeList[attr] : -1 let value = prop.ToString() where !string.IsNullOrEmpty(value) select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = product.ProductID, AttributeID = attributeID, Value = value, LanguageID = "1", AttributeCode = attr, }).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.ProductID, Price = decimal.Round(product.RetailPrice, 4).ToString("0.00", CultureInfo.InvariantCulture), CostPrice = decimal.Round(product.SalesPrice.Value, 4).ToString("0.00", CultureInfo.InvariantCulture), TaxRate = "19", //TODO: Calculate this! MinimumQuantity = 1, CommercialStatus = product.ProductStatus } }, #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.ProductID, QuantityOnHand = 0, StockType = "Assortment", StockStatus = product.ProductStatus } }, #endregion }; assortmentList.Add(assortment); } catch (Exception ex) { log.WarnFormat("Batch update failed with message : {0}", ex.Message); } } done += toProcess.Count(); } #region delete unused foreach (var vProdVendor in currentProductGroupVendors) { if (vProdVendor.ProductGroupID == -1) { //productGroupVendorRepo.Delete(vProdVendor); } } #endregion // Creates a new instance of VendorAssortmentBulk(Passes in the AssortmentList defined above, vendorID and DefaultVendorID) using (var vendorAssortmentBulk = new VendorAssortmentBulk(assortmentList, VendorID, VendorID)) { vendorAssortmentBulk.Init(unit.Context); vendorAssortmentBulk.Sync(unit.Context); } log.AuditInfo("Products processing finished. Processed " + done + " products"); } }
/* * <Products version="1.0"issuedate=20100323"> * <Product id="0011B006AA"> * <Content lang="nl"> * <Description>Printer Inktjet PIXMA iP6220D Kleur</Description> * <Brand id="CAN">Canon</Brand> * <UNSPSC id="43212104">Inkjetprinters</UNSPSC> * <Specifications> * <Specification id="000027"> * <Description>printerfunctionaliteit</Description> * <Value>Printer</Value> * </Specification> * <Specification id="000029"> * <Description>type printer</Description> * <Value>Inktjet</Value> * </Specification> * <Specification id="000026"> * <Description>printernaam</Description> * <Value>PIXMA iP6220D</Value> * </Specification> * <Specification id="000028"> * <Description>type output</Description> * <Value>Kleur</Value> * </Specification> * </Specifications> * </Content> * <Content lang="uk"> * <Description>Printer Inktjet PIXMA iP6220D Colour</Description> * <Brand id="CAN">Canon</Brand> * <UNSPSC id="43212104">Inkjet printers</UNSPSC> * <Specifications> * <Specification id="000027"> * <Description>printer functionality</Description> * <Value>Printer</Value> * </Specification> * <Specification id="000029"> * <Description>printer type</Description> * <Value>Inktjet</Value> * </Specification> * <Specification id="000026"> * <Description>printer name</Description> * <Value>PIXMA iP6220D</Value> * </Specification> * <Specification id="000028"> * <Description>Output type</Description> * <Value>Colour</Value> * </Specification> * </Specifications> * </Content> * <Identifiers> * <OEM>0011B006AA</OEM> * <CustomerID>0011B006AA</CustomerID> * <EANProduct>4960999258423</EANProduct> * <EANMasterCarton></EANMasterCarton> * <OnetrailPDI></OnetrailPDI> * </Identifiers> * <Purchase> * <Stock>0</Stock> * <MOQ>1</MOQ> * <Status>O</Status> * <ReplacedBy></ReplacedBy> * </Purchase> * <Images> * <Product>http://images.alpha-international.eu/products/originals/0011B006AA.JPG</Product> * <Brand>http://images.alpha-international.eu/brands/originals/CAN.GIF</Brand> * </Images> * <Logistics> * <ProductsPerOuterCarton></ProductsPerOuterCarton> * <ProductsPerLayer></ProductsPerLayer> * <ProductsPerPallet></ProductsPerPallet> * <OuterCartonPerPallet></OuterCartonPerPallet> * <Weights unit="gr"> * <ProductWeight>5600</ProductWeight> * <OuterCartonWeight></OuterCartonWeight> * </Weights> * <Measures unit="cm"> * <ProductLength>50.5</ProductLength> * <ProductWidth>37.5</ProductWidth> * <ProductHeight>24.5</ProductHeight> * <OuterCartonLength></OuterCartonLength> * <OuterCartonWidth></OuterCartonWidth> * <OuterCartonHeight></OuterCartonHeight> * </Measures> * </Logistics> * <Compatibility> * <Product>CAN22165</Product> * <Product>CAN22167</Product> * <Product>CAN22166</Product> * <Product>CAN22168</Product> * </Compatibility> * <CrossSell> * </CrossSell> * </Product> * <Product ... > * .... * </Product> * </Products> */ #endregion private bool ProcessXml(XDocument doc, Dictionary <string, ProductIdentifier> relations) { try { var products = from pr in doc.Element("Products").Elements("Product") group pr by new { pr.Element("Identifiers").Element("OEM").Value, ID = pr.Attribute("id").Value } into pro let p = pro.First() let identifiers = p.Element("Identifiers") let purchase = p.Element("Purchase") let oemCode = identifiers.Element("OEM").Value let images = p.Element("Images") let compat = p.Element("Compatibility") select new { VenderItemNumber = p.Attribute("id").Value, Content = from c in p.Elements("Content") let brand = c.Element("Brand") let cat = c.Element("UNSPSC") select new { Language = c.Attribute("lang").Value, Description = c.Element("Description").Value, Brand = new { ID = brand.Attribute("id").Value, Name = brand.Value }, Category = new { ID = cat.Attribute("id").Value, Name = cat.Value } , Specs = c.Element("Specifications") == null ? null : from s in c.Element("Specifications").Elements("Specification") select new { ID = s.Attribute("id").Value, Desc = s.Element("Description").Value, s.Element("Value").Value } }, Identifiers = new { OEM = ((oemCode == "ONBEKEND" || string.IsNullOrEmpty(oemCode)) ? p.Attribute("id").Value : oemCode), CustomerID = identifiers.Element("CustomerID").Value, EAN = identifiers.Element("EANProduct").Value }, InStock = purchase.Element("Stock") != null ? (int)purchase.Element("Stock") : 0, MinQuantity = purchase.Element("MOQ") != null ? (int)purchase.Element("MOQ") : 1, Status = purchase.Element("Status").Value, Price = purchase.Element("Price") != null ? (decimal?)purchase.Element("Price") : null, ProductImages = from i in images.Elements("Product") select i.Value, CompatibleProducts = new ProductIdentifier { productID = p.Attribute("id").Value, compatibleProducts = (compat != null ? (from cp in compat.Elements("Product") select cp.Value).ToList() : new List <string>()) } }; using (var unit = GetUnitOfWork()) { int counter = 0; int total = products.Count(); int totalNumberOfProductsToProcess = total; log.InfoFormat("Start import {0} products", total); var productAttributes = unit.Scope.Repository <ProductAttributeMetaData>().GetAll(c => c.VendorID == VendorID).ToList(); var 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>(); RelatedProductTypes relatedProductTypes = new RelatedProductTypes(unit.Scope.Repository <RelatedProductType>()); var relatedProductType = relatedProductTypes.SyncRelatedProductTypes("CompatibleProducts"); var AttributeMapping = (from p in products where p.Content != null && p.Content.Count() > 0 from a in p.Content.Where(x => x.Specs != null).SelectMany(x => x.Specs) select a.Desc).Distinct().ToArray(); List <ProductAttributeMetaData> attributes; SetupAttributes(unit, AttributeMapping, out attributes, null); foreach (var product in products) { if (counter == 100) { counter = 0; log.InfoFormat("Still need to process {0} of {1}; {2} done;", totalNumberOfProductsToProcess, total, total - totalNumberOfProductsToProcess); } totalNumberOfProductsToProcess--; counter++; //use english content for all non-language specifics var enContent = product.Content.FirstOrDefault(c => c.Language.ToUpper() == "UK"); if (enContent == null) { enContent = product.Content.FirstOrDefault(c => c.Language.ToUpper() == "NL"); } var assortment = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem { #region BrandVendor BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>() { new VendorAssortmentBulk.VendorImportBrand() { VendorID = VendorID, VendorBrandCode = enContent.Brand.ID, ParentBrandCode = null, Name = enContent.Brand.Name } }, #endregion #region GeneralProductInfo VendorProduct = new VendorAssortmentBulk.VendorProduct { VendorItemNumber = product.Identifiers.OEM, CustomItemNumber = product.VenderItemNumber, ShortDescription = enContent.Description.Length > 150 ? enContent.Description.Substring(0, 150) : enContent.Description, LongDescription = enContent.Description, LineType = null, LedgerClass = null, ProductDesk = null, ExtendedCatalog = null, VendorID = VendorID, DefaultVendorID = DefaultVendorID, VendorBrandCode = enContent.Brand.ID, Barcode = product.Identifiers.EAN, VendorProductGroupCode1 = enContent.Category.ID, VendorProductGroupCodeName1 = enContent.Category.Name }, #endregion #region RelatedProducts RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>() { new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportRelatedProduct { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = product.VenderItemNumber, RelatedProductType = relatedProductType.Type, RelatedCustomItemNumber = product.VenderItemNumber } }, #endregion #region Attributes VendorImportAttributeValues = (from att in product.Content.Where(x => x.Specs != null).SelectMany(x => x.Specs) let attributeID = attributeList.ContainsKey(att.Desc) ? attributeList[att.Desc] : -1 where !string.IsNullOrEmpty(att.Value) select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = product.VenderItemNumber, AttributeID = attributeID, Value = att.Value, LanguageID = 1.ToString(), AttributeCode = att.Desc, }).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.VenderItemNumber, Price = product.Price.HasValue ? product.Price.Value.ToString("0.00", CultureInfo.InvariantCulture) : null, CostPrice = null, TaxRate = "19", MinimumQuantity = product.MinQuantity, 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.VenderItemNumber, QuantityOnHand = 0, StockType = "Assortment", StockStatus = product.Status } }, #endregion }; assortmentList.Add(assortment); } using (var vendorAssortmentBulk = new VendorAssortmentBulk(assortmentList, VendorID, VendorID)) { vendorAssortmentBulk.Init(unit.Context); vendorAssortmentBulk.Sync(unit.Context); } return(true); } } catch (Exception ex) { log.AuditFatal(String.Format("Failed to process file"), ex); return(false); } }