private AuctionProduct GetAuctionProductDetail(DataRow row) { var ap = AuctionProduct.CreateAuctionProduct(); ap.Product = row["Producto"].ToString(); ap.UnitValue = float.Parse(row["Valor unitario"].ToString()); ap.Quantity = float.Parse(row["Cantidad"].ToString()); ap.TotalValue = float.Parse(row["Total producto"].ToString()); return(ap); }
public IActionResult Create(AuctionProductCreateViewModel model) { ViewBag.Categories = _context.Categories.ToList(); if (model.Uploads == null) { ModelState.AddModelError("Uploads", "The Photo field is required."); } if (model.Uploads.Length < 4) { ModelState.AddModelError("Uploads", "The auction must have at least 4 photos."); } if (model.BuyNowPrice <= model.StartPrice) { ModelState.AddModelError("BuyNowPrice", "Buy now price must be bigger than start price."); } if (model.EndDate < DateTime.Now.AddDays(1)) { ModelState.AddModelError("EndDate", "Auction must be at least 24 hours."); } if (ModelState.IsValid) { AuctionProduct product = new AuctionProduct() { Name = model.Name, About = model.About, BuyNowPrice = model.BuyNowPrice, StartPrice = model.StartPrice, EndDate = model.EndDate, CategoryId = model.CategoryId }; _context.AuctionProducts.Add(product); _context.SaveChanges(); foreach (var item in model.Uploads) { AuctionProductGallery productGallery = new AuctionProductGallery(); var fileName = _fileManager.Upload(item); productGallery.Photo = fileName; productGallery.AuctionProductId = _context.AuctionProducts.OrderByDescending(x => x.Id).FirstOrDefault().Id; _context.AuctionProductGalleries.Add(productGallery); _context.SaveChanges(); } return(RedirectToAction("index")); } return(View(model)); }
public async Task <IActionResult> Create(AuctionViewModel auction) { var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var user = await _db.Seller.Where(s => s.Id == claim.Value).FirstOrDefaultAsync(); if (ModelState.IsValid) { AuctionHeader auctionHeader = new AuctionHeader() { Seen = false, SellerId = claim.Value, User = user, BeginDate = auction.AuctionHeader.BeginDate, EndDate = auction.AuctionHeader.EndDate, CurrentPrice = auction.AuctionHeader.CurrentPrice, PriceStep = auction.AuctionHeader.PriceStep }; _db.AuctionHeader.Add(auctionHeader); await _db.SaveChangesAsync(); foreach (var item in auction.Products) { var productSale = await _db.ProductSale.Include(p => p.Product).Where(p => p.Id == item.ProductSale.Id).FirstOrDefaultAsync(); productSale.Units -= item.Quantity; var product = await _db.Product.Where(p => p.Id == productSale.ProductId).FirstOrDefaultAsync(); var auctionProduct = new AuctionProduct() { ProductId = product.Id, Product = product, AuctionId = auctionHeader.Id, AuctionHeader = auctionHeader, Quantity = item.Quantity }; _db.AuctionProduct.Add(auctionProduct); } await _db.SaveChangesAsync(); return(RedirectToAction("Index", "Seller")); } foreach (var modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Console.WriteLine(error.ErrorMessage); } } return(RedirectToAction(nameof(Select))); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity <NotiBuy>() .HasMany(n => n.OrderDetails) .WithOne() .OnDelete(DeleteBehavior.SetNull); modelBuilder.Entity <NotiSell>() .HasMany(n => n.OrderDetails) .WithOne() .OnDelete(DeleteBehavior.SetNull); #region *******************Seeding Data******************* for (int i = 1; i <= 10; i++) { //Seeding 10 products... modelBuilder.Entity <Product>() .HasData(new Product() { Id = i * 10, Name = "Producto" + i.ToString(), Description = "Descripcion del producto" + i.ToString() }); //Seeding 10 users(customers) RegisterUser(modelBuilder, (i * 10 + 1).ToString(), SD.CustomerUser, "Customer" + i.ToString()); //Seeding 10 seller RegisterSeller(modelBuilder, (i * 10 + 2).ToString(), SD.SellerUser, "Seller" + i.ToString()); //Seeding 10 products sales modelBuilder.Entity <ProductSale>() .HasData(new ProductSale() { Id = i * 1000 + 3, ProductId = i * 10, SellerId = (i * 10 + 2).ToString(), Units = i + 1, Price = (i + 15) / 2, Image = @"/images/default.png" }); //Seeding Notifications of Role Upgrade if (i % 3 == 0) { modelBuilder.Entity <NotiRole>() .HasData(new NotiRole() { Id = i * 10 + 4, UserID = (i * 10 + 1).ToString(), Message = "Customer" + i.ToString() + " wants to become a Seller", SendToUser = "******", Seen = false }); } //Seeding Auctions if (i % 2 != 0) { AuctionHeader ah; if (i == 3 || i == 5) // Seeding two Ended Auctions { ah = new AuctionHeader() { BeginDate = DateTime.Now, CurrentPrice = i + 3, EndDate = DateTime.Now, Id = i * 10 + 5, PriceStep = i, SellerId = (i * 10 + 2).ToString() }; } else if (i == 1) //Seeding an upcoming auction { ah = new AuctionHeader() { BeginDate = DateTime.Now.AddHours(5), CurrentPrice = i, EndDate = DateTime.Now.AddHours(i + 10), Id = i * 10 + 5, PriceStep = i, SellerId = (i * 10 + 2).ToString() }; } else { ah = new AuctionHeader() { BeginDate = DateTime.Now, CurrentPrice = i + 3, EndDate = DateTime.Now.AddHours(i + 10), Id = i * 10 + 5, PriceStep = i, SellerId = (i * 10 + 2).ToString() }; } var ap = new AuctionProduct() { AuctionId = i * 10 + 5, Id = i * 10 + 6, ProductId = i * 10, Quantity = (i + 1) / 2, }; var ap1 = new AuctionProduct() { AuctionId = i * 10 + 5, Id = i * 100000 + 6, ProductId = (i + 1) * 10, Quantity = (i + 1) / 2, }; if (i != 5 && i != 1) // The auction 5 and 1 does not contain an auctionUser { if (i == 3) // Auction 3 has two auctionUser { var auser2 = new AuctionUser() { Id = i * 10000000 + 7, AuctionId = i * 10 + 5, UserId = ((i + 1) * 10 + 1).ToString(), LastPriceOffered = i + 1 }; modelBuilder.Entity <AuctionUser>() .HasData(auser2); } var auser = new AuctionUser() { Id = i * 10 + 7, AuctionId = i * 10 + 5, UserId = (i * 10 + 1).ToString(), LastPriceOffered = i + 3 }; modelBuilder.Entity <AuctionUser>() .HasData(auser); } modelBuilder.Entity <AuctionHeader>() .HasData(ah); modelBuilder.Entity <AuctionProduct>() .HasData(ap); modelBuilder.Entity <AuctionProduct>() .HasData(ap1); } } //Adding just one more product sale, Seller 8 is selling product 1 modelBuilder.Entity <ProductSale>() .HasData(new ProductSale() { Id = 8 * 10000 + 3, ProductId = 1 * 10, SellerId = (8 * 10 + 2).ToString(), Units = 8 + 1, Price = (8 + 15) / 2 }); //Defining Roles string [] roles = { SD.CustomerUser, SD.ManagerUser, SD.SellerUser }; foreach (var role in roles) { modelBuilder.Entity <IdentityRole>().HasData(new IdentityRole() { Id = "a18be9c0" + role, Name = role, NormalizedName = role }); } //Adding an Admin RegisterSeller(modelBuilder, "21123111111", SD.ManagerUser, "admin"); #endregion }
protected override void Process() { try { log.Debug("Start import auction items"); Concentrator.SpiderServiceSoapClient soap = new Concentrator.SpiderServiceSoapClient(); XDocument products = XDocument.Parse(soap.GetAssortment(int.Parse(ConfigurationManager.AppSettings["ConnectorID"].ToString())).OuterXml); using (AuctionDataContext ctx = new AuctionDataContext(ConfigurationManager.ConnectionStrings["Staging"].ConnectionString)) { var auctionProductList = (from p in ctx.AuctionProducts select p).ToList(); Dictionary <int, Product> existingProducts = new Dictionary <int, Product>(); log.DebugFormat("Xml contains {0} products", products.Root.Elements("Product").Count()); foreach (var r in products.Root.Elements("Product")) { var auctionProduct = (from a in auctionProductList where a.AuctionProductID == int.Parse(r.Attribute("CustomProductID").Value) select a).FirstOrDefault(); log.DebugFormat("Start import product {0}", r.Attribute("CustomProductID").Value); try { if (auctionProduct == null) { var product = (from p in ctx.Products where p.ProductID == int.Parse(r.Attribute("CustomProductID").Value) select p).FirstOrDefault(); if (product == null) { #region add product Brand brand = (from b in ctx.Brands where b.BrandCode == r.Element("Brand").Element("Code").Value.Trim() select b).FirstOrDefault(); if (brand != null) { decimal unitprice = decimal.Parse(r.Element("Price").Element("UnitPrice").Value, CultureInfo.InvariantCulture); decimal costprice = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture); string shortDescription = r.Element("Content").Attribute("ShortDescription").Value; string longDescription = r.Element("Content").Attribute("LongDescription").Value; int?taxRateID = (from t in ctx.TaxRates where t.TaxRate1.HasValue && (t.TaxRate1.Value * 100) == decimal.Parse(r.Element("Price").Attribute("TaxRate").Value, CultureInfo.InvariantCulture) select t.TaxRateID).SingleOrDefault(); if (!taxRateID.HasValue) { taxRateID = 1; } DateTime temppdDate = DateTime.MinValue; DateTime?pdDate = null; if (DateTime.TryParse(r.Element("Stock").Attribute("PromisedDeliveryDate").Value, out temppdDate)) { if (temppdDate == DateTime.MinValue && temppdDate == DateTime.MaxValue) { pdDate = null; } else { pdDate = temppdDate; } } product = new Product { ProductID = int.Parse(r.Attribute("CustomProductID").Value), ShortDescription = shortDescription, LongDescription = longDescription, ManufacturerID = r.Attribute("ManufacturerID").Value, BrandID = brand.BrandID, TaxRateID = taxRateID.Value, UnitPrice = unitprice, UnitCost = costprice, IsCustom = false, LineType = string.IsNullOrEmpty(r.Attribute("LineType").Value) ? "S" : r.Attribute("LineType").Value.Trim(), ProductStatus = r.Element("Price").Attribute("CommercialStatus").Value, IsVisible = true, CreationTime = DateTime.Now, LastModificationTime = DateTime.Now, ExtendedCatalog = false, PromisedDeliveryDate = pdDate }; ctx.Products.InsertOnSubmit(product); ctx.SubmitChanges(); } else { log.DebugFormat("Brand {0} does not exists for {1}", r.Element("Brand").Element("Code").Value.Trim(), r.Attribute("CustomProductID").Value); continue; } #endregion } auctionProduct = new AuctionProduct() { AuctionProductID = int.Parse(r.Attribute("CustomProductID").Value) }; ctx.AuctionProducts.InsertOnSubmit(auctionProduct); auctionProductList.Add(auctionProduct); } var bsc = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSC" select b.Attribute("InStock").Value).FirstOrDefault(); int bscStock = 0; int.TryParse(bsc, out bscStock); var bscOEM = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCOEM" select b.Attribute("InStock").Value).FirstOrDefault(); int bscOEMStock = 0; int.TryParse(bscOEM, out bscOEMStock); var bscCostPrices = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSC" select b.Attribute("CostPrice").Value).FirstOrDefault(); decimal BSCCostPrice = 0; if (bscCostPrices != null) { BSCCostPrice = decimal.Parse(bscCostPrices, CultureInfo.InvariantCulture); } decimal DC10CostPrice = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture); auctionProduct.AuctionBSCStock = bscStock; auctionProduct.AuctionDC10Stock = int.Parse(r.Element("Stock").Attribute("InStock").Value); auctionProduct.AuctionOEMStock = bscOEMStock; auctionProduct.BSCCostPrice = BSCCostPrice; auctionProduct.DC10CostPrice = DC10CostPrice; auctionProduct.QuantityToReceive = int.Parse(r.Element("Stock").Attribute("QuantityToReceive").Value);; auctionProduct.StockStatus = r.Element("Stock").Attribute("StockStatus").Value; ctx.SubmitChanges(); } catch (Exception ex) { log.Error("error insert product", ex); } } } log.Debug("Start cleanup auctionproducts"); using (AuctionDataContext context = new AuctionDataContext(ConfigurationManager.ConnectionStrings["Staging"].ConnectionString)) { #region Vendor Assortment List <int> itemNumbers = (from r in products.Root.Elements("Product") select int.Parse(r.Attribute("CustomProductID").Value)).ToList(); List <AuctionProduct> unused = (from c in context.AuctionProducts select c).ToList(); unused.RemoveAll(c => itemNumbers.Contains(c.AuctionProductID)); #endregion if (unused != null && unused.Count > 0) { context.AuctionProducts.DeleteAllOnSubmit(unused); } context.SubmitChanges(); } log.Debug("Finish cleanup assormtent"); log.DebugFormat("Product import Completed On: {0}", DateTime.Now); } catch (Exception ex) { log.Error("Error import products", ex); } }
protected override void Process() { foreach (Connector connector in base.Connectors) //already filtered { log.DebugFormat("Start Process auction export for {0}", connector.Name); DateTime start = DateTime.Now; try { log.Debug("Start import auction items"); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = new XDocument(soap.GetAssortment(connector.ConnectorID, null, true)); Processor processor = new Processor(products, log, connector); DateTime? lastUpdate = null; using (WebsiteDataContext ctx = new WebsiteDataContext(connector.ConnectionString)) { var auctionProductList = (from p in ctx.AuctionProducts select new { AuctionProduct = p, BrandCode = p.Product.Brand.BrandCode, Product = p.Product }).ToList(); if (auctionProductList.Count > 0) { lastUpdate = (from lu in auctionProductList let update = (lu.AuctionProduct.LastModificationTime.HasValue ? lu.AuctionProduct.LastModificationTime.Value : lu.AuctionProduct.CreationTime) select update).Max(); } Dictionary <int, Product> existingProducts = new Dictionary <int, Product>(); log.DebugFormat("Xml contains {0} products", products.Root.Elements("Product").Count()); log.Info("Start import brands"); processor.ImportBrands(); log.Info("Finish import brands"); log.Info("Start import productgroups"); processor.ImportProductGroups(false); log.Info("Finish import productgroups"); var allProductGroups = (from p in ctx.ProductGroups select p).ToList(); var productGroupMappings = (from p in ctx.ProductGroupMappings group p by p.ProductGroupID into grouped select grouped).ToDictionary(x => x.Key, y => y.ToList()); foreach (var r in products.Root.Elements("Product")) { #region Get Concentrator Product ID int concentratorProductID = Utility.GetConcentratorProductID(connector, r, log); if (concentratorProductID == 0) { continue; } AuctionProduct auctionProduct = null; Product product = null; if (connector.UseConcentratorProductID) { auctionProduct = (from a in auctionProductList where a.Product.ConcentratorProductID.HasValue && a.Product.ConcentratorProductID.Value == concentratorProductID select a.AuctionProduct).FirstOrDefault(); product = (from a in ctx.Products where a.ConcentratorProductID.HasValue && a.ConcentratorProductID.Value == concentratorProductID select a).FirstOrDefault(); } else { auctionProduct = (from a in auctionProductList where a.Product.ProductID == concentratorProductID select a.AuctionProduct).FirstOrDefault(); product = (from a in ctx.Products where a.ProductID == concentratorProductID select a).FirstOrDefault(); } #endregion try { List <ProductGroup> productgroups = new List <ProductGroup>(); foreach (var productGroupNode in r.Element("ProductGroupHierarchy").Elements("ProductGroup")) { var productGroups = (from pg in allProductGroups where pg.BackendProductGroupCode == productGroupNode.Attribute("ID").Value select pg).ToList(); List <string> parentNodes = new List <string>() { productGroupNode.Attribute("ID").Value }; var parent = productGroupNode.Element("ProductGroup"); while (parent != null) { parentNodes.Add(parent.Attribute("ID").Value); parent = parent.Element("ProductGroup"); } string path = String.Join("/", parentNodes.ToArray()); ProductGroup group = null; foreach (var g in productGroups) { string groupPath = g.GetProductGroupCodeTree(); if (groupPath == path) { group = g; break; } } if (group != null) { productgroups.Add(group); } } if (r.Element("Price") != null) { decimal unitprice = decimal.Parse(r.Element("Price").Element("UnitPrice").Value, CultureInfo.InvariantCulture); decimal costprice = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture); string shortDescription = r.Element("Content").Attribute("ShortDescription").Value; string longDescription = r.Element("Content").Attribute("LongDescription").Value; string backendDescription = string.Empty; if (connector.ImportCommercialText) { backendDescription = longDescription; //shortDescription = r.Element("Content").Attribute("ShortContentDescription").Value; //if (!string.IsNullOrEmpty(r.Element("Content").Attribute("LongContentDescription").Value)) //longDescription = r.Element("Content").Attribute("LongContentDescription").Value; } int?taxRateID = (from t in ctx.TaxRates where t.TaxRate1.HasValue && (t.TaxRate1.Value * 100) == decimal.Parse(r.Element("Price").Attribute("TaxRate").Value, CultureInfo.InvariantCulture) select t.TaxRateID).FirstOrDefault(); if (!taxRateID.HasValue) { taxRateID = 1; } if (auctionProduct == null) { #region Create New (Auction) Product Brand brand = (from b in ctx.Brands where b.BrandCode == r.Element("Brands").Element("Brand").Attribute("BrandID").Value.Trim() select b).FirstOrDefault(); if (brand != null) { //DateTime temppdDate = DateTime.MinValue; //DateTime? pdDate = null; //if (DateTime.TryParse(r.Element("Stock").Attribute("PromisedDeliveryDate").Value, out temppdDate)) //{ // if (temppdDate == DateTime.MinValue && temppdDate == DateTime.MaxValue) // pdDate = null; // else // pdDate = temppdDate; //} if (product == null) { if (!connector.UseConcentratorProductID) { //create stub product with identity_insert on string cmd = String.Format( @" INSERT INTO Products (ProductID, ShortDescription,LongDescription,brandid,taxrateid,iscustom,isvisible,extendedcatalog , canmodifyprice,creationtime,lastmodificationtime ) VALUES( {0}, '{1}','{2}', {3},{4},0,0,1,0,getdate(), getdate()) ", concentratorProductID, shortDescription, longDescription, brand.BrandID, taxRateID.Value); ctx.ExecuteCommand(cmd); product = ctx.Products.Single(x => x.ProductID == concentratorProductID); product.IsVisible = false; ctx.SubmitChanges(); } else { product = new Product { //ProductID = int.Parse(r.Attribute("CustomProductID").Value), //ProductGroupID = subprodid, IsVisible = false, CreationTime = DateTime.Now, LastModificationTime = DateTime.Now }; ctx.Products.InsertOnSubmit(product); } if (!string.IsNullOrEmpty(backendDescription)) { product.BackEndDescription = backendDescription; } DateTime pdDate; if (DateTime.TryParse(r.Element("Stock").Attribute("PromisedDeliveryDate").Value, out pdDate)) { if (pdDate != DateTime.MinValue && pdDate != DateTime.MaxValue) { product.PromisedDeliveryDate = pdDate; } } } if (!product.IsVisible) { product.UnitPrice = unitprice; product.ShortDescription = shortDescription; product.LongDescription = longDescription; product.ManufacturerID = r.Attribute("ManufacturerID").Value; product.BrandID = brand.BrandID; product.TaxRateID = taxRateID.Value; product.UnitCost = 0; product.IsCustom = false; product.LineType = string.IsNullOrEmpty(r.Attribute("LineType").Value) ? "S" : r.Attribute("LineType").Value.Trim(); product.ProductStatus = r.Element("Price").Attribute("CommercialStatus").Value; } product.CustomProductID = r.Attribute("CustomProductID").Value; product.ConcentratorProductID = int.Parse(r.Attribute("ProductID").Value); ctx.SubmitChanges(); } else { log.DebugFormat("Product {0} does not have a price in xml", r.Attribute("ProductID").Value); } if (product != null) { auctionProduct = new AuctionProduct() { AuctionProductID = product.ProductID, CreationTime = DateTime.Now }; ctx.AuctionProducts.InsertOnSubmit(auctionProduct); auctionProductList.Add(new { AuctionProduct = auctionProduct, BrandCode = product.Brand.BrandCode, Product = product }); } else { log.WarnFormat("Cannot create new product info for product ID : {0}", concentratorProductID); continue; } #endregion } } else { log.DebugFormat("Brand {0} does not exists for {1}", r.Elements("Brands").Elements("Brand").FirstOrDefault().Attribute("BrandID").Value.Trim(), r.Attribute("ProductID").Value); continue; } if (auctionProduct == null) { log.WarnFormat("Cannot create new auction product info for product ID : {0}", concentratorProductID); continue; } #region Parse Stock Data var bsc = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSC" select b.Attribute("InStock").Value).FirstOrDefault(); int bscStock = 0; int.TryParse(bsc, out bscStock); var bscOEM = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCOEM" select b.Attribute("InStock").Value).FirstOrDefault(); int bscOEMStock = 0; int.TryParse(bscOEM, out bscOEMStock); //DEMO var bscDemo = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCDEMO" select b.Attribute("InStock").Value).FirstOrDefault(); int bscDemoStock = 0; int.TryParse(bscDemo, out bscDemoStock); //DMGBOX var bscDMGBOX = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCDMGBOX" select b.Attribute("InStock").Value).FirstOrDefault(); int bscDMGBOXStock = 0; int.TryParse(bscDMGBOX, out bscDMGBOXStock); //DMGITEM var bscDMGITEM = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCDMGITEM" select b.Attribute("InStock").Value).FirstOrDefault(); int bscDMGITEMStock = 0; int.TryParse(bscDMGITEM, out bscDMGITEMStock); //INCOMPL var bscINCOMPL = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCINCOMPL" select b.Attribute("InStock").Value).FirstOrDefault(); int bscINCOMPLStock = 0; int.TryParse(bscINCOMPL, out bscINCOMPLStock); //RETURN var bscRETURN = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCRETURN" select b.Attribute("InStock").Value).FirstOrDefault(); int bscRETURNStock = 0; int.TryParse(bscRETURN, out bscRETURNStock); //USED var bscUSED = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCUSED" select b.Attribute("InStock").Value).FirstOrDefault(); int bscUSEDStock = 0; int.TryParse(bscUSED, out bscUSEDStock); //COSTPRice var totalBscStock = bscDemoStock + bscDMGBOXStock + bscDMGITEMStock + bscINCOMPLStock + bscRETURNStock + bscUSEDStock + bscStock; var bscCostPrices = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSC" select b.Attribute("CostPrice").Value).FirstOrDefault(); decimal BSCCostPrice = 0; if (bscCostPrices != null) { BSCCostPrice = decimal.Parse(bscCostPrices, CultureInfo.InvariantCulture); } decimal DC10CostPrice = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture); #endregion if (auctionProduct.AuctionBSCStock != totalBscStock || auctionProduct.AuctionDC10Stock != int.Parse(r.Element("Stock").Attribute("InStock").Value) || auctionProduct.AuctionOEMStock != bscOEMStock || auctionProduct.BSCCostPrice != BSCCostPrice || auctionProduct.DC10CostPrice != DC10CostPrice || auctionProduct.AuctionDEMOStock != bscDemoStock || auctionProduct.AuctionDMGBOXStock != bscDMGBOXStock || auctionProduct.AuctionDMGITEMStock != bscDMGITEMStock || auctionProduct.AuctionINCOMPLStock != bscINCOMPLStock || auctionProduct.AuctionRETURNStock != bscRETURNStock || auctionProduct.AuctionUSEDStock != bscUSEDStock || auctionProduct.AuctionMYVEILStock != bscStock || auctionProduct.QuantityToReceive != int.Parse(r.Element("Stock").Attribute("QuantityToReceive").Value) || auctionProduct.StockStatus != r.Element("Stock").Attribute("StockStatus").Value) { auctionProduct.LastModificationTime = DateTime.Now; } auctionProduct.AuctionBSCStock = totalBscStock; auctionProduct.AuctionDC10Stock = int.Parse(r.Element("Stock").Attribute("InStock").Value); auctionProduct.AuctionOEMStock = bscOEMStock; auctionProduct.BSCCostPrice = BSCCostPrice; auctionProduct.AuctionDEMOStock = bscDemoStock; auctionProduct.AuctionDMGBOXStock = bscDMGBOXStock; auctionProduct.AuctionDMGITEMStock = bscDMGITEMStock; auctionProduct.AuctionINCOMPLStock = bscINCOMPLStock; auctionProduct.AuctionRETURNStock = bscRETURNStock; auctionProduct.AuctionUSEDStock = bscUSEDStock; auctionProduct.AuctionMYVEILStock = bscStock; auctionProduct.DC10CostPrice = DC10CostPrice; auctionProduct.QuantityToReceive = int.Parse(r.Element("Stock").Attribute("QuantityToReceive").Value);; auctionProduct.StockStatus = r.Element("Stock").Attribute("StockStatus").Value; ctx.SubmitChanges(); processor.ImportProductGroupMapping(ctx, productgroups, productGroupMappings, auctionProduct.AuctionProductID, concentratorProductID); ctx.SubmitChanges(); if (!product.ConcentratorProductID.HasValue) { product.ConcentratorProductID = int.Parse(r.Attribute("ProductID").Value); ctx.SubmitChanges(); } } catch (Exception ex) { log.Error("error insert product", ex); } } //log.Info("Start import productgroupmapppings"); //processor.ImportProductGroupMapping(ctx, connector); //log.Info("Finish import productgroupmapppings"); log.Debug("Start cleanup auctionproducts"); var cItemNumbers = (from r in products.Root.Elements("Product") select new { concentratorProductID = r.Attribute("ProductID").Value, customProductID = r.Attribute("CustomProductID").Value }).ToList(); List <string> xmlProducts = new List <string>(); if (connector.UseConcentratorProductID) { xmlProducts = (from c in cItemNumbers where c.concentratorProductID != String.Empty select c.concentratorProductID).ToList(); } else { foreach (var c in cItemNumbers.Select(x => x.customProductID)) { int tmp = 0; if (Int32.TryParse(c, out tmp)) { xmlProducts.Add(tmp.ToString()); } } } List <AuctionProduct> siteProducts = new List <AuctionProduct>(); if (connector.UseConcentratorProductID) { var tempSiteProducts = (from c in ctx.AuctionProducts where c.Product.ConcentratorProductID.HasValue select new { concentratorProductID = c.Product.ConcentratorProductID.Value.ToString(), auctionItem = c }).ToList(); foreach (var p in cItemNumbers) { tempSiteProducts.RemoveAll(c => c.concentratorProductID == p.concentratorProductID.ToString()); } siteProducts = tempSiteProducts.Select(x => x.auctionItem).ToList(); if (siteProducts != null && siteProducts.Count > 0) { ctx.AuctionProducts.DeleteAllOnSubmit(siteProducts); } ctx.SubmitChanges(); var delProds = (from c in ctx.AuctionProducts where !c.Product.ConcentratorProductID.HasValue select c).ToList(); log.DebugFormat("Delete {0} items without concentrator productid", delProds.Count); ctx.AuctionProducts.DeleteAllOnSubmit(delProds); ctx.SubmitChanges(); } else { siteProducts = (from c in ctx.AuctionProducts select c).ToList(); foreach (var p in cItemNumbers) { siteProducts.RemoveAll(c => c.AuctionProductID.ToString() == p.customProductID); } if (siteProducts != null && siteProducts.Count > 0) { ctx.AuctionProducts.DeleteAllOnSubmit(siteProducts); } ctx.SubmitChanges(); } } log.Debug("Finish cleanup assormtent"); // processor.CleanUpProductGroupMapping(); log.Debug("Start import productattributes"); processor.ProcessAttributes(soap, connector, true, lastUpdate, false); log.Debug("Finish import productattributes"); log.DebugFormat("Auction Product import Completed On: {0}", DateTime.Now); } catch (Exception ex) { log.Error("Error import products", ex); } log.DebugFormat("Finish Process auction import for {0}", connector.Name); } }