public void Delete(int productId, int categoryId) { Product_Category_Mapping m = GetProduct_Category_Mapping(productId, categoryId); if (m != null) { db.Product_Category_Mapping.Remove(m); } }
private void AddProductCategoryMappingToDbContext() { ProductRepository pr = _container.Resolve <ProductRepository>(); { Domain.Core.Product product = pr.GetProduct(_product.Id); var pcm = new Product_Category_Mapping { CategoryId = _treeViewSelectedCategoryNode.Id, ProductId = _product.Id, IsFeaturedProduct = false, DisplayOrder = 1 }; product.Product_Category_Mapping.Add(pcm); pr.Save(); product.Product_Category_Mapping = product.Product_Category_Mapping; } }
public void Create(Product_Category_Mapping item) { db.Product_Category_Mapping.Add(item); }
public void Update(Product_Category_Mapping item) { db.Entry(item).State = EntityState.Modified; }
void InitSyncProducts(object ctx) { SynchronizationContext ctxx = (SynchronizationContext)ctx; try { kamscrin_npcommerceEntities storeEntities = new kamscrin_npcommerceEntities(); ctxx.Send(writeToProductProgress, "Opteniendo Lista de Grupos"); List <Group> categories = SQLHelper.getCategories(); int num1 = 0; ctxx.Send(writeToProductProgress, string.Format("Procesando {0} Categorias", (object)categories.Count)); ctxx.Send(setProductProgressInitialValues, (object)categories.Count); foreach (Group group in categories) { Group g = group; ctxx.Send(writeToProductProgress, $"Categoria -> {g.SDescripcion} - {g.SGrupo}"); Console.WriteLine(); Category ct = new Category() { Name = g.SDescripcion, Description = g.SDescripcion, MetaDescription = g.SGrupo, MetaKeywords = g.SGrupo_Padre, PageSize = 10 }; Category category = ((IQueryable <Category>)storeEntities.Categories).FirstOrDefault <Category>(x => x.MetaDescription == g.SGrupo_Padre); Category exist = ((IQueryable <Category>)storeEntities.Categories).FirstOrDefault <Category>(x => x.MetaDescription == g.SGrupo); if (exist == null) { if (category != null) { num1 = category.Id; } ct.ParentCategoryId = num1; storeEntities.Categories.Add(ct); storeEntities.SaveChanges(); if (((IQueryable <UrlRecord>)storeEntities.UrlRecords).FirstOrDefault <UrlRecord>(x => x.EntityId == ct.Id && x.EntityName == "Category") == null) { storeEntities.UrlRecords.Add(new UrlRecord() { EntityId = ct.Id, EntityName = "Category", Slug = RemoveSpecialCharacters(ct.Name), IsActive = true }); storeEntities.SaveChanges(); } } else { exist.Description = g.SDescripcion; exist.Name = g.SDescripcion; exist.MetaDescription = g.SGrupo; exist.MetaKeywords = g.SGrupo_Padre; exist.PageSize = 10; storeEntities.SaveChanges(); if (((IQueryable <UrlRecord>)storeEntities.UrlRecords).FirstOrDefault <UrlRecord>(x => x.EntityId == exist.Id && x.EntityName == "Category") == null) { storeEntities.UrlRecords.Add(new UrlRecord() { EntityId = exist.Id, EntityName = "Category", Slug = RemoveSpecialCharacters(exist.Name), IsActive = true }); storeEntities.SaveChanges(); } } ctxx.Send(increaseProductProgressValues, group); } ctxx.Send(writeToProductProgress, $"Obteniendo Prductos"); List <PCGRAF_Product> products = SQLHelper.getProducts(); ctxx.Send(writeToProductProgress, string.Format("Procesando {0} Productos", products.Count)); ctxx.Send(setProductProgressInitialValues, products.Count); int num2 = 0; foreach (PCGRAF_Product p in products) { ctxx.Send(writeToProductProgress, $"Prducto { p.SCodigo_Producto} - P1: {p.P1} - P2: {p.P2} - P3: {p.P3} - P4: {p.P4}"); try { label_37: Decimal P1 = 0; Decimal P2 = 0; Decimal P3 = 0; Decimal P4 = 0; if (p.P1 != null) { Decimal.TryParse(p.P1, out P1); } if (p.P2 != null) { Decimal.TryParse(p.P2, out P2); } if (p.P3 != null) { Decimal.TryParse(p.P3, out P3); } if (p.P4 != null) { Decimal.TryParse(p.P4, out P4); } Category exist_cat = storeEntities.Categories.FirstOrDefault <Category>(x => x.MetaDescription == p.SGrupo); Product product = new Product() { Name = p.SDescripcion_Inventario, ShortDescription = p.SDescripcion_Inventario, Price1 = new Decimal?(P1), Price2 = new Decimal?(P2), Price3 = new Decimal?(P3), Price4 = new Decimal?(P4), MetaKeywords = p.SCodigo_Producto, Sku = p.SCodigo_Producto, ProductTypeId = 5, CreatedOnUtc = DateTime.UtcNow, StockQuantity = 9999, VisibleIndividually = true, OrderMaximumQuantity = 999, OrderMinimumQuantity = 1 }; Product exist_prod = storeEntities.Products.FirstOrDefault <Product>(x => x.MetaKeywords == p.SCodigo_Producto); if (exist_prod != null) { Product_Category_Mapping productCategoryMapping = storeEntities.Product_Category_Mapping.FirstOrDefault <Product_Category_Mapping>(x => x.CategoryId == exist_cat.Id && x.ProductId == exist_prod.Id); if (productCategoryMapping == null && exist_prod != null) { storeEntities.Product_Category_Mapping.Add(new Product_Category_Mapping() { CategoryId = exist_cat.Id, ProductId = exist_prod.Id }); storeEntities.SaveChanges(); } else if (productCategoryMapping != null && exist_prod != null) { productCategoryMapping.ProductId = exist_prod.Id; productCategoryMapping.CategoryId = exist_cat.Id; exist_prod.Price1 = new Decimal?(Decimal.Parse(p.P1)); exist_prod.Price2 = new Decimal?(Decimal.Parse(p.P2)); exist_prod.Price3 = new Decimal?(Decimal.Parse(p.P3)); exist_prod.Price4 = new Decimal?(Decimal.Parse(p.P4)); exist_prod.Name = p.SDescripcion_Inventario; exist_prod.ShortDescription = p.SDescripcion_Inventario; exist_prod.MetaKeywords = p.SCodigo_Producto; exist_prod.OrderMinimumQuantity = 1; exist_prod.OrderMaximumQuantity = 999; exist_prod.ProductTypeId = 5; storeEntities.SaveChanges(); } else { storeEntities.Products.Add(product); storeEntities.SaveChanges(); Thread.Sleep(500); storeEntities.Product_Category_Mapping.Add(new Product_Category_Mapping() { CategoryId = exist_cat.Id, ProductId = product.Id }); storeEntities.SaveChanges(); } if (storeEntities.UrlRecords.FirstOrDefault <UrlRecord>(x => x.EntityId == exist_prod.Id && x.EntityName == "Product") == null) { storeEntities.UrlRecords.Add(new UrlRecord() { EntityId = exist_prod.Id, EntityName = "Product", Slug = RemoveSpecialCharacters(exist_prod.Name), IsActive = true }); storeEntities.SaveChanges(); } } else { storeEntities.Products.Add(product); storeEntities.SaveChanges(); storeEntities.UrlRecords.Add(new UrlRecord() { EntityId = product.Id, EntityName = "Product", Slug = RemoveSpecialCharacters(p.SDescripcion_Inventario), IsActive = true }); storeEntities.Product_Category_Mapping.Add(new Product_Category_Mapping() { CategoryId = exist_cat.Id, ProductId = product.Id }); storeEntities.SaveChanges(); } ctxx.Send(increaseProductProgressValues, p); } catch (Exception ex) { //if (num2 < 5) //{ //ctxx.Send(writeToProductProgress, string.Format("Error trying to insert data; Try {0} of 5", (object)(num2 + 1))); ctxx.Send(writeToProductProgress, "Error details: " + ex.Message); ctxx.Send(writeToProductProgress, "Error details: " + ex.StackTrace); // ++num2; //} //else // goto label_37; } } ctxx.Send(writeToProductProgress, $"Prducto y Categorias Sincronizados!"); } catch (Exception ex) { ctxx.Send(writeToProductProgress, "Error details: " + ex.Message); ctxx.Send(writeToProductProgress, "Error details: " + ex.StackTrace); } }