Esempio n. 1
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;
        }
Esempio n. 2
0
 /// <summary>
 /// 团购直接下单、待付款
 /// </summary>
 /// <param name="user"></param>
 /// <param name="product"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public Order CreateOrderDirect(User user, NativeProduct product, int count)
 {
     var order = new Order();
     if (count == 0 || product == null)
     {
         throw new InvalidOperationException("没有任何商品购买");
     }
     order.OrderItems = new List<OrderItem>();
     var orderItem = new OrderItem();
     orderItem.Id = Guid.NewGuid();
     orderItem.Product = product;
     orderItem.Quantity = count;
     orderItem.Order = order;
     order.OrderItems.Add(orderItem);
     order.User = user;
     order.DeliveryAddress = user.DeliveryAddress;
     order.Status = DictOrderStatus.创建;//先创建订单,付款需要用到订单号
     _orderRepository.Add(order);
     _repositoryContext.Commit();
     return order;
 }
Esempio n. 3
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();
        }
Esempio n. 4
0
 // 通过商品对象和分类对象来创建商品分类对象
 public static ProductCategorization CreateCategorization(NativeProduct product, Category category)
 {
     return new ProductCategorization(product.Id, category.Id);
 }