Beispiel #1
0
        // 将指定的商品从其所属的商品分类中移除
        public void Uncategorize(NativeProduct product, Category category = null)
        {
            Expression<Func<ProductCategorization, bool>> specExpress = null
                ;
            if (category == null)
                specExpress = p => p.ProductId == product.Id;
            else
                specExpress = p => p.ProductId == product.Id && p.CategoryId == category.Id;
            var productCategorization = _productCategorizationRepository.GetByExpression(specExpress);
            if (productCategorization == null) return;

            _productCategorizationRepository.Remove(productCategorization);
            _repositoryContext.Commit();
        }
Beispiel #2
0
        // 将指定的商品归类到指定的商品分类中。
        public ProductCategorization Categorize(NativeProduct product, Category category)
        {
            if (product == null)
                throw new ArgumentNullException("product");
            if (category == null)
                throw new ArgumentNullException("category");

            var productCategorization =
                _productCategorizationRepository.GetBySpecification(
                    Specification<ProductCategorization>.Eval(c => c.ProductId == product.Id));
            if (productCategorization == null)
            {
                productCategorization = ProductCategorization.CreateCategorization(product, category);
                _productCategorizationRepository.Add(productCategorization);
            }
            else
            {
                productCategorization.CategoryId = category.Id;
                _productCategorizationRepository.Update(productCategorization);
            }

            _repositoryContext.Commit();
            return productCategorization;
        }
 // 通过商品对象和分类对象来创建商品分类对象
 public static ProductCategorization CreateCategorization(NativeProduct product, Category category)
 {
     return new ProductCategorization(product.Id, category.Id);
 }