public void InsertOrUpdateCategoryProductMapping(Product product, int?categoryId) { Category category = _categoryRepository.FindCategoryById(categoryId ?? 0); category = category ?? _categoryRepository.FindCategoryByName("Other"); ProductCategoryMapping productCategoryMapping = _productCategoryMappingRepository.FindByProductIdNoXmlUpdateIsUpdated( product.Id, false, false ); if (productCategoryMapping != null) { productCategoryMapping.CategoryId = category.Id; _productCategoryMappingRepository.Update(productCategoryMapping); _productCategoryMappingRepository.Save(); } else { productCategoryMapping = _productCategoryMappingRepository.FindByProductIdCategoryId( product.Id, category.Id); if (productCategoryMapping == null) { _productCategoryMappingRepository.Add(new ProductCategoryMapping() { ProductId = product.Id, CategoryId = category.Id, IsFeaturedProduct = false, DisplayOrder = 0 }); _productCategoryMappingRepository.Save(); } } }
public ProductCategoryMapping SaveProductCategoryMapping(ProductCategoryMapping productCategoryMapping) { ProductCategoryMapping savedProductCategoryMapping = _thyMenaProductCategoryMappingRepository.Add(productCategoryMapping); _thyMenaProductCategoryMappingRepository.Save(); return(savedProductCategoryMapping); }