private void FinalseMapping() { using (var db = new EFTest.DB()) { var products = db.Products.Select( product => new { ID = product.ID, Asin = product.Asin }).ToDictionary( product => product.Asin, product => product.ID); var options = db.DeliveryOptions.ToDictionary( option => Tuple.Create(option.Service, option.Price), option => option.ID); foreach (var item in this.temporaryMapping) { this.finalMapping.Rows.Add(new object[] { products[item.Item1], options[item.Item2]}); } } }
public static void CopyFusePump(string feedPath, string tableName, string connectionString) { var productTable = new DataTable("Product"); productTable.Columns.Add("ID", typeof(string)); productTable.Columns.Add("Asin", typeof(string)); productTable.Columns.Add("Modified", typeof(DateTime)); var deliveryOptionTable = new DataTable("DeliveryOption"); deliveryOptionTable.Columns.Add("ID", typeof(int)); deliveryOptionTable.Columns.Add("Service", typeof(string)); deliveryOptionTable.Columns.Add("Price", typeof(decimal)); var productDeliveryOptionTable = new System.Data.DataTable("DeliveryOption"); productDeliveryOptionTable.Columns.Add("Product", typeof(int)); productDeliveryOptionTable.Columns.Add("Option", typeof(int)); var productHash = new HashSet<string>(); var productDeliveryOptionList = new List<Tuple<string, System.Data.DataRow>>(); using (var reader = XmlReader.Create(feedPath)) { while (reader.ReadToFollowing("item")) { ParseProduct(deliveryOptionTable, productHash, productDeliveryOptionList, reader); } } PopulateProductsTable(productTable, productHash); using (var db = new EFTest.DB()) { using (var bulk = new System.Data.SqlClient.SqlBulkCopy(db.Database.Connection as SqlConnection)) { BulkInsert(productTable, "Content.Product", bulk); BulkInsert(deliveryOptionTable, "Content.Content.DeliveryOption", bulk); var products = db.Products.Select(p => new { ID = p.ID, Asin = p.Asin }).ToArray(); var deliveryOptions = db.DeliveryOptions.ToArray(); foreach (var item in productDeliveryOptionList) { productDeliveryOptionTable.Rows.Add(new object[] { products.Where(p => p.Asin == item.Item1).Single().ID, deliveryOptions.Where(d => d.Service == item.Item2["Service"] as string && d.Price == (decimal)item.Item2["Price"]).Single().ID}); } BulkInsert(productDeliveryOptionTable, "Content.ProductDeliveryOption.DeliveryOption", bulk); } } }
public EFTest.Product Get(int id) { using (var db = new EFTest.DB()) { var product = db.Products.Where(p => p.ID == id).SingleOrDefault(); if (product == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } return product; } }
public static void Enrich() { using (var db = new EFTest.DB()) { var dbProduct = db.Products.OrderBy(p => p.Modified).First(); //var dbProduct = db.Products.Where(p => p.Name == "B006QYGOOK").First(); try { var amzonProduct = Amazon.Mapping.x.GetProduct(dbProduct.Asin); var relationships = amzonProduct.Relationships.Where(r => r.RelationshipType == Amazon.Mapping.RelationshipType.Variation); foreach (var relationship in relationships) { var variation = GetOrCreateProductFromAsin(db, relationship.Asin); CreateVariantIfRequired(db, dbProduct, variation, relationship.Direction, relationship.Dimensions); } } finally { dbProduct.Modified = DateTime.UtcNow; db.SaveChanges(); } } }