private void CommitToDatabase(List<AsinProductData> asinData) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < asinData.Count; i++) { var a = asinData[i]; AmazonListing dbEntry = new AmazonListing(); dbEntry.Asin = a.Asin; dbEntry.BuyBox = a.BuyBoxTotalPrice; dbEntry.CurrentlyOwnBuyBox = a.CurrentlyOwnBuyBox; dbEntry.Date = DateTime.Now; dbEntry.SalesRank = a.SalesRankTopLevel; if (db.AmazonListings.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0 && db.AmazonListings.Local.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0) { db.AmazonListings.Add(dbEntry); } if (i % 1000 == 0) { this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / asinData.Count, i, asinData.Count); this.StatusPercentage = i * 100 / asinData.Count; db.SaveChanges(); } } db.SaveChanges(); } }
private void CommitToDatabase(List <AsinProductData> asinData) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < asinData.Count; i++) { var a = asinData[i]; AmazonListing dbEntry = new AmazonListing(); dbEntry.Asin = a.Asin; dbEntry.BuyBox = a.BuyBoxTotalPrice; dbEntry.CurrentlyOwnBuyBox = a.CurrentlyOwnBuyBox; dbEntry.Date = DateTime.Now; dbEntry.SalesRank = a.SalesRankTopLevel; if (db.AmazonListings.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0 && db.AmazonListings.Local.Where(o => o.Asin.Equals(dbEntry.Asin) && o.Date.Equals(dbEntry.Date)).Count() == 0) { db.AmazonListings.Add(dbEntry); } if (i % 1000 == 0) { this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / asinData.Count, i, asinData.Count); this.StatusPercentage = i * 100 / asinData.Count; db.SaveChanges(); } } db.SaveChanges(); } }
/// <summary> /// Retrieves the last updated time from the database. /// </summary> public void GetLastUpdated() { if (ServiceId == null) { throw new Exception("Service Status cannot be committed to the database because the ServiceId is null"); } using (var db = new CheapeesEntities()) { var entry = db.ServiceStatuses.Where(o => o.ServiceId.Equals(this.ServiceId)).SingleOrDefault(); if (entry != null) { this.LastUpdated = (DateTime)entry.LastSuccessfulUpdate; } } }
public List<string> GetAsinList() { List<string> asins = new List<string>(); List<Inventory> listings = new List<Inventory>(); using (var db = new CheapeesEntities()) { listings = db.Inventories.Where(o => o.Asin != null).ToList(); } foreach (var listing in listings) { if (listing.Asin != null && listing.Asin.Length != 0) asins.Add(listing.Asin); } return asins; }
public void CommitServiceStatus() { using (var db = new CheapeesEntities()) { var entry = db.ServiceStatuses.Where(o => o.ServiceId.Equals(this.ServiceId)).SingleOrDefault(); if (entry != null) { entry.LastSuccessfulUpdate = this.LastUpdated; } else { ServiceStatus status = new ServiceStatus(); status.ServiceId = this.ServiceId; status.LastSuccessfulUpdate = this.LastUpdated; db.ServiceStatuses.Add(status); } db.SaveChanges(); } }
public List <string> GetAsinList() { List <string> asins = new List <string>(); List <Inventory> listings = new List <Inventory>(); using (var db = new CheapeesEntities()) { listings = db.Inventories.Where(o => o.Asin != null).ToList(); } foreach (var listing in listings) { if (listing.Asin != null && listing.Asin.Length != 0) { asins.Add(listing.Asin); } } return(asins); }
public void UpdateData() { if (string.IsNullOrEmpty(this.Asin)) { return; } List <AmazonListing> srList; using (var db = new CheapeesEntities()) { srList = db.AmazonListings.Where(o => o.Asin.Equals(this.Asin)).ToList(); } series.Points.Clear(); foreach (var sr in srList) { series.Points.Add(new DataPoint(sr.Date.ToOADate(), (double)sr.SalesRank)); } }
private void CommitToDatabase(List<AsinPrepData> asinData) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < asinData.Count; i++) { var a = asinData[i]; if (db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).Count() == 0 && db.AmazonPrepInstructions.Local.Where(o => o.Asin.Equals(a.Asin)).Count() == 0) { AmazonPrepInstruction dbEntry = new AmazonPrepInstruction(); dbEntry.Asin = a.Asin; dbEntry.Labelling = a.Labelling; dbEntry.PrepRequired = a.Prep; db.AmazonPrepInstructions.Add(dbEntry); } else { AmazonPrepInstruction dbEntry = db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).SingleOrDefault(); if (dbEntry != null) { dbEntry.Labelling = a.Labelling; dbEntry.PrepRequired = a.Prep; } } if (i % 1000 == 0) { this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / asinData.Count, i, asinData.Count); this.StatusPercentage = i * 100 / asinData.Count; db.SaveChanges(); } } db.SaveChanges(); } }
private List <string> GetAsinList() { this.StatusDescription = string.Format("Getting local ASIN list"); List <string> asins = new List <string>(); List <Inventory> listings = new List <Inventory>(); using (var db = new CheapeesEntities()) { listings = db.Inventories.Where(o => o.Asin != null).ToList(); } foreach (var listing in listings) { if (listing.Asin != null && listing.Asin.Length != 0) { asins.Add(listing.Asin); } } return(asins); }
private void CommitToDatabase(List <AsinPrepData> asinData) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < asinData.Count; i++) { var a = asinData[i]; if (db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).Count() == 0 && db.AmazonPrepInstructions.Local.Where(o => o.Asin.Equals(a.Asin)).Count() == 0) { AmazonPrepInstruction dbEntry = new AmazonPrepInstruction(); dbEntry.Asin = a.Asin; dbEntry.Labelling = a.Labelling; dbEntry.PrepRequired = a.Prep; db.AmazonPrepInstructions.Add(dbEntry); } else { AmazonPrepInstruction dbEntry = db.AmazonPrepInstructions.Where(o => o.Asin.Equals(a.Asin)).SingleOrDefault(); if (dbEntry != null) { dbEntry.Labelling = a.Labelling; dbEntry.PrepRequired = a.Prep; } } if (i % 1000 == 0) { this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / asinData.Count, i, asinData.Count); this.StatusPercentage = i * 100 / asinData.Count; db.SaveChanges(); } } db.SaveChanges(); } }
private void CommitToDatabase(List <ChannelAdvisorSale> sales) { using (var db = new CheapeesEntities()) { foreach (var sale in sales) { if (db.MerchantFulfilledSales.Local.Count(o => (o.Invoice.Equals(sale.Invoice) && o.Sku.Equals(sale.SKU))) == 0 && db.MerchantFulfilledSales.Count(o => (o.Invoice.Equals(sale.Invoice) && o.Sku.Equals(sale.SKU))) == 0) { MerchantFulfilledSale dbSale = new MerchantFulfilledSale(); dbSale.Invoice = sale.Invoice; dbSale.Marketplace = sale.Marketplace; dbSale.OrderTime = sale.OrderTime; dbSale.Quantity = sale.Quantity; dbSale.Sku = sale.SKU; dbSale.UnitPrice = sale.UnitPrice; db.MerchantFulfilledSales.Add(dbSale); } } db.SaveChanges(); } }
private void CommitToDatabase(List <InventoryItem> inventory) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < inventory.Count; i++) { var item = inventory[i]; var entity = db.Inventories.Where(o => o.Sku.Equals(item.Sku)).FirstOrDefault(); if (entity == null) { entity = new Inventory(); entity.Asin = item.Asin; entity.Sku = item.Sku; entity.Title = item.Title; db.Inventories.Add(entity); } else { entity.Asin = item.Asin; entity.Sku = item.Sku; entity.Title = item.Title; } if (i % 1000 == 0) { // Save every 1000 records this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({0}/{1})", i * 100.0 / inventory.Count, i, inventory.Count); this.StatusPercentage = (i * 100) / inventory.Count; db.SaveChanges(); } } db.SaveChanges(); } }
public void CommitToDatabase(List <FbaInventoryQuantity> fbaQuantities) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; // Clear table first db.AmazonFulfilledInventories.RemoveRange(db.AmazonFulfilledInventories); db.SaveChanges(); for (int i = 0; i < fbaQuantities.Count; i++) { var qty = fbaQuantities[i]; AmazonFulfilledInventory dbInv = new AmazonFulfilledInventory(); dbInv.Asin = qty.Asin; dbInv.FbaSku = qty.Sku; dbInv.Fnsku = qty.Fnsku; dbInv.FulfillableQuantity = qty.FulfillableQuantity; dbInv.InboundReceivingQuantity = qty.InboundReceivingQuantity; dbInv.InboundShippedQuantity = qty.InboundShippedQuantity; dbInv.InboundWorkingQuantity = qty.InboundWorkingQuantity; dbInv.TotalQuantity = qty.TotalQuantity; db.AmazonFulfilledInventories.Add(dbInv); if (i % 1000 == 0) { this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / fbaQuantities.Count, i, fbaQuantities.Count); this.StatusPercentage = i * 100 / fbaQuantities.Count; db.SaveChanges(); } } db.SaveChanges(); } }
private void CommitToDatabase(List<ChannelAdvisorSale> sales) { using (var db = new CheapeesEntities()) { foreach (var sale in sales) { if (db.MerchantFulfilledSales.Local.Count(o => (o.Invoice.Equals(sale.Invoice) && o.Sku.Equals(sale.SKU))) == 0 && db.MerchantFulfilledSales.Count(o => (o.Invoice.Equals(sale.Invoice) && o.Sku.Equals(sale.SKU))) == 0) { MerchantFulfilledSale dbSale = new MerchantFulfilledSale(); dbSale.Invoice = sale.Invoice; dbSale.Marketplace = sale.Marketplace; dbSale.OrderTime = sale.OrderTime; dbSale.Quantity = sale.Quantity; dbSale.Sku = sale.SKU; dbSale.UnitPrice = sale.UnitPrice; db.MerchantFulfilledSales.Add(dbSale); } } db.SaveChanges(); } }
private void CommitToDatabase(List<InventoryItem> inventory) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < inventory.Count; i++) { var item = inventory[i]; var entity = db.Inventories.Where(o => o.Sku.Equals(item.Sku)).FirstOrDefault(); if (entity == null) { entity = new Inventory(); entity.Asin = item.Asin; entity.Sku = item.Sku; entity.Title = item.Title; db.Inventories.Add(entity); } else { entity.Asin = item.Asin; entity.Sku = item.Sku; entity.Title = item.Title; } if (i % 1000 == 0) { // Save every 1000 records this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({0}/{1})", i * 100.0 / inventory.Count, i, inventory.Count); this.StatusPercentage = (i * 100) / inventory.Count; db.SaveChanges(); } } db.SaveChanges(); } }
public void CommitToDatabase(List<FbaInventoryQuantity> fbaQuantities) { using (var db = new CheapeesEntities()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; // Clear table first db.AmazonFulfilledInventories.RemoveRange(db.AmazonFulfilledInventories); db.SaveChanges(); for (int i = 0; i < fbaQuantities.Count; i++) { var qty = fbaQuantities[i]; AmazonFulfilledInventory dbInv = new AmazonFulfilledInventory(); dbInv.Asin = qty.Asin; dbInv.FbaSku = qty.Sku; dbInv.Fnsku = qty.Fnsku; dbInv.FulfillableQuantity = qty.FulfillableQuantity; dbInv.InboundReceivingQuantity = qty.InboundReceivingQuantity; dbInv.InboundShippedQuantity = qty.InboundShippedQuantity; dbInv.InboundWorkingQuantity = qty.InboundWorkingQuantity; dbInv.TotalQuantity = qty.TotalQuantity; db.AmazonFulfilledInventories.Add(dbInv); if (i % 1000 == 0) { this.StatusDescription = string.Format("Committing to database - {0:0.00}% ({1}/{2})", i * 100.0 / fbaQuantities.Count, i, fbaQuantities.Count); this.StatusPercentage = i * 100 / fbaQuantities.Count; db.SaveChanges(); } } db.SaveChanges(); } }
public void UpdateData() { if (string.IsNullOrEmpty(this.Asin)) return; List<AmazonListing> srList; using (var db = new CheapeesEntities()) { srList = db.AmazonListings.Where(o => o.Asin.Equals(this.Asin)).ToList(); } series.Points.Clear(); foreach (var sr in srList) { series.Points.Add(new DataPoint(sr.Date.ToOADate(), (double)sr.SalesRank)); } }
public void CommitServiceStatus() { using (var db = new CheapeesEntities()) { var entry = db.ServiceStatuses.Where(o => o.ServiceId.Equals(this.ServiceId)).SingleOrDefault(); if (entry != null) entry.LastSuccessfulUpdate = this.LastUpdated; else { ServiceStatus status = new ServiceStatus(); status.ServiceId = this.ServiceId; status.LastSuccessfulUpdate = this.LastUpdated; db.ServiceStatuses.Add(status); } db.SaveChanges(); } }
/// <summary> /// Retrieves the last updated time from the database. /// </summary> public void GetLastUpdated() { if (ServiceId == null) throw new Exception("Service Status cannot be committed to the database because the ServiceId is null"); using (var db = new CheapeesEntities()) { var entry = db.ServiceStatuses.Where(o => o.ServiceId.Equals(this.ServiceId)).SingleOrDefault(); if (entry != null) this.LastUpdated = (DateTime)entry.LastSuccessfulUpdate; } }
private List<string> GetAsinList() { this.StatusDescription = string.Format("Getting local ASIN list"); List<string> asins = new List<string>(); List<Inventory> listings = new List<Inventory>(); using (var db = new CheapeesEntities()) { listings = db.Inventories.Where(o => o.Asin != null).ToList(); } foreach (var listing in listings) { if (listing.Asin != null && listing.Asin.Length != 0) asins.Add(listing.Asin); } return asins; }
private void DownloadSalesData() { try { this.StatusDescription = string.Format("Creating ChannelAdvisor Client"); //Create OrderService client and ready it for request string devKey = System.Configuration.ConfigurationManager.AppSettings["CaDevK"]; string devPW = System.Configuration.ConfigurationManager.AppSettings["CaDevPw"]; //int profileID = 32001327; string accountID = System.Configuration.ConfigurationManager.AppSettings["CaAcct"]; ; APICredentials cred = new APICredentials(); cred.DeveloperKey = devKey; cred.Password = devPW; OrderServiceSoapClient ordClient = new OrderServiceSoapClient(); //Get latest order date in DB, and pull all orders since then DateTime beginTime; using (var db = new CheapeesEntities()) { beginTime = (DateTime)db.MerchantFulfilledSales.OrderByDescending(o => o.OrderTime).FirstOrDefault().OrderTime; } OrderCriteria criteria = new OrderCriteria(); criteria.OrderCreationFilterBeginTimeGMT = beginTime; criteria.OrderCreationFilterEndTimeGMT = DateTime.Now; criteria.DetailLevel = "High"; List<ChannelAdvisorSale> listOfSales = new List<ChannelAdvisorSale>(); int page = 1; criteria.PageNumberFilter = page; //Issue requests this.StatusDescription = string.Format("Requesting sales data since latest sale ({0})", beginTime); APIResultOfArrayOfOrderResponseItem response = ordClient.GetOrderList(cred, accountID, criteria); int numberOfOrders = 0; //When everything has been retrieved, pages will be returned empty and should exit loop while (response.ResultData.Length != 0) { numberOfOrders += response.ResultData.Length; this.StatusDescription = string.Format("Downloading sales data: {0} orders retrieved", numberOfOrders); foreach (OrderResponseDetailHigh order in response.ResultData) { foreach (OrderLineItemItem item in order.ShoppingCart.LineItemSKUList) { ChannelAdvisorSale sale = new ChannelAdvisorSale(); sale.SKU = item.SKU; sale.Quantity = item.Quantity; sale.Marketplace = item.ItemSaleSource; sale.UnitPrice = item.UnitPrice; sale.OrderTime = ((DateTime)order.OrderTimeGMT).ToLocalTime(); sale.Invoice = order.OrderID.ToString(); listOfSales.Add(sale); } } //Get next page of results page++; criteria.PageNumberFilter = page; response = ordClient.GetOrderList(cred, accountID, criteria); } CommitToDatabase(listOfSales); } catch (Exception e) { throw new Exception(string.Format("ChannelAdvisorOrderService - {0}", e.Message)); } }
private void DownloadSalesData() { try { this.StatusDescription = string.Format("Creating ChannelAdvisor Client"); //Create OrderService client and ready it for request string devKey = System.Configuration.ConfigurationManager.AppSettings["CaDevK"]; string devPW = System.Configuration.ConfigurationManager.AppSettings["CaDevPw"]; //int profileID = 32001327; string accountID = System.Configuration.ConfigurationManager.AppSettings["CaAcct"];; APICredentials cred = new APICredentials(); cred.DeveloperKey = devKey; cred.Password = devPW; OrderServiceSoapClient ordClient = new OrderServiceSoapClient(); //Get latest order date in DB, and pull all orders since then DateTime beginTime; using (var db = new CheapeesEntities()) { beginTime = (DateTime)db.MerchantFulfilledSales.OrderByDescending(o => o.OrderTime).FirstOrDefault().OrderTime; } OrderCriteria criteria = new OrderCriteria(); criteria.OrderCreationFilterBeginTimeGMT = beginTime; criteria.OrderCreationFilterEndTimeGMT = DateTime.Now; criteria.DetailLevel = "High"; List <ChannelAdvisorSale> listOfSales = new List <ChannelAdvisorSale>(); int page = 1; criteria.PageNumberFilter = page; //Issue requests this.StatusDescription = string.Format("Requesting sales data since latest sale ({0})", beginTime); APIResultOfArrayOfOrderResponseItem response = ordClient.GetOrderList(cred, accountID, criteria); int numberOfOrders = 0; //When everything has been retrieved, pages will be returned empty and should exit loop while (response.ResultData.Length != 0) { numberOfOrders += response.ResultData.Length; this.StatusDescription = string.Format("Downloading sales data: {0} orders retrieved", numberOfOrders); foreach (OrderResponseDetailHigh order in response.ResultData) { foreach (OrderLineItemItem item in order.ShoppingCart.LineItemSKUList) { ChannelAdvisorSale sale = new ChannelAdvisorSale(); sale.SKU = item.SKU; sale.Quantity = item.Quantity; sale.Marketplace = item.ItemSaleSource; sale.UnitPrice = item.UnitPrice; sale.OrderTime = ((DateTime)order.OrderTimeGMT).ToLocalTime(); sale.Invoice = order.OrderID.ToString(); listOfSales.Add(sale); } } //Get next page of results page++; criteria.PageNumberFilter = page; response = ordClient.GetOrderList(cred, accountID, criteria); } CommitToDatabase(listOfSales); } catch (Exception e) { throw new Exception(string.Format("ChannelAdvisorOrderService - {0}", e.Message)); } }