private Inventory MapToInventoryDto(AmznListingItem listingItem) { Inventory inventoryData = new Inventory(); inventoryData.SKU = listingItem.Item.ItemLookupCode; inventoryData.Item = listingItem.Quantity.ToString(); inventoryData.RestockDateSpecified = false; inventoryData.SwitchFulfillmentToSpecified = false; return(inventoryData); }
private Price MapToPriceDto(AmznListingItem listingItem) { OverrideCurrencyAmount oca = new OverrideCurrencyAmount(); oca.currency = BaseCurrencyCodeWithDefault.USD; oca.Value = Math.Round(listingItem.Price, 4); Price priceData = new Price(); priceData.SKU = listingItem.Item.ItemLookupCode; priceData.StandardPrice = oca; return(priceData); }
public void SavePriceDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs) { using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (AmazonEnvelopeMessage msg in msgs) { Price priceData = (Price)msg.Item; AmznListingItem listingItem = dataContext.AmznListingItems .Single(p => p.Item.ItemLookupCode.Equals(priceData.SKU) && p.MarketplaceID == _marketplace.ID && p.IsActive); listingItem.Price = priceData.StandardPrice.Value; } dataContext.SaveChanges(); } }
public void SaveInventoryDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs) { using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (AmazonEnvelopeMessage msg in msgs) { Inventory inventoryData = (Inventory)msg.Item; AmznListingItem listingItem = dataContext.AmznListingItems .Single(p => p.Item.ItemLookupCode.Equals(inventoryData.SKU) && p.MarketplaceID == _marketplace.ID && p.IsActive); listingItem.Quantity = Convert.ToInt32(inventoryData.Item); } dataContext.SaveChanges(); } }
public List <AmznListingItem> SaveProductDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs) { var added = _dataContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(p => p.Entity).Cast <AmznListingItem>(); List <AmznListingItem> listingItems = new List <AmznListingItem>(); using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (var msg in msgs) { Product product = (Product)msg.Item; if (dataContext.Items.Any(p => p.ItemLookupCode.Equals(product.SKU))) { AmznListingItem listingItem = dataContext.AmznListingItems .SingleOrDefault(p => p.Item.ItemLookupCode.Equals(product.SKU) && p.MarketplaceID == _marketplace.ID); listingItems.Add(added.Single(p => p.Item.ItemLookupCode.Equals(product.SKU))); if (listingItem == null) { listingItem = new AmznListingItem(); listingItem.Item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(product.SKU)); listingItem.Sku = product.SKU; listingItem.Marketplace = dataContext.AmznMarketplaces.Single(p => p.ID == _marketplace.ID); listingItem.OpenDate = DateTime.UtcNow; listingItem.LastSyncTime = DateTime.UtcNow; listingItem.ASIN = "UNKNOWN"; listingItem.Quantity = 0; listingItem.Price = 0; listingItem.Title = product.DescriptionData.Title; } listingItem.IsActive = true; } } dataContext.SaveChanges(); } return(listingItems); }
private List <Product> MapToProductDto(List <AmznListingItem> listingItems) { List <Product> products = new List <Product>(); for (int i = 0; i < listingItems.Count; i++) { AmznListingItem listingItem = listingItems[i]; ProductData productData = _productMapperFactory.GetProductData(listingItem.Item); products.Add(productData.GetProductDto(listingItem.Title)); if (i == 0 && listingItem.Item.ItemClass != null && !listingItem.Item.ItemClass.AnyActiveListing(_marketplace.ID)) { products.Add(productData.GetParentProductDto(listingItem.Title)); } } return(products); }
private void ImportAmznData(IEnumerable <MainEntry> entries) { using (berkeleyEntities dataContext = new berkeleyEntities()) { BerkeleyEntities.Amazon.AmazonServices amznServices = new BerkeleyEntities.Amazon.AmazonServices(); foreach (MainEntry entry in entries) { Item item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(entry.Sku)); entry.UPC = item.GTIN; } AmznMarketplace marketplace = dataContext.AmznMarketplaces.First(); var entriesWithUPC = entries.Where(p => !string.IsNullOrEmpty(p.UPC)); var results = amznServices.GetMatchingProductForId(marketplace.ID, entriesWithUPC.Select(p => p.UPC)); foreach (var result in results) { MainEntry entry = entriesWithUPC.First(p => p.UPC.Equals(result.Id)); if (result.IsSetProducts() && result.Products.IsSetProduct()) { Product product = result.Products.Product.First(); foreach (var attributeSet in product.AttributeSets.Any.Cast <XmlElement>()) { var nodes = attributeSet.ChildNodes.OfType <XmlNode>(); if (nodes.Any(p => p.LocalName.Equals("Feature"))) { StringBuilder features = new StringBuilder(); features.Append("<ul>"); foreach (XmlNode node in nodes.Where(p => p.LocalName.Equals("Feature"))) { features.AppendFormat("<li>{0}</li>", node.InnerText); } features.Append("</ul>"); entry.AmznDescription = features.ToString(); } if (nodes.Any(p => p.LocalName.Equals("Title"))) { XmlNode node = nodes.Single(p => p.LocalName.Equals("Title")); entry.AmznTitle = node.InnerText; } } } } foreach (MainEntry entry in entries) { Item item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(entry.Sku)); AmznListingItem listingItem = item.AmznListingItems.FirstOrDefault(); if (listingItem != null) { entry.Asin = listingItem.ASIN; } } var competitivePriceResults = amznServices.GetLowestOfferListingsForAsin(marketplace.ID, entries.Where(p => !string.IsNullOrWhiteSpace(p.Asin)).Select(p => p.Asin)); foreach (var result in competitivePriceResults) { MainEntry entry = entries.Where(p => p.Asin != null).First(p => p.Asin.Equals(result.ASIN)); if (result.IsSetProduct() && result.Product.IsSetLowestOfferListings() && result.Product.LowestOfferListings.IsSetLowestOfferListing()) { var competitivePrice = result.Product.LowestOfferListings.LowestOfferListing.First(); entry.AmznPrice = competitivePrice.Price.LandedPrice.Amount; } } } }