Ejemplo n.º 1
0
 /// <summary>
 /// 下单,没有付款
 /// </summary>
 /// <param name="user"></param>
 /// <param name="shoppingCartItems"></param>
 /// <returns></returns>
 public Order CreateOrderByItem(User user, List<ShoppingCartItem> shoppingCartItems)
 {
     var order = new Order();
     if (shoppingCartItems == null || !shoppingCartItems.Any())
     {
         throw new InvalidOperationException("购物篮中没有任何物品");
     }
     order.OrderItems = new List<OrderItem>();
     foreach (var shoppingCartItem in shoppingCartItems)
     {
         if (shoppingCartItem != null && shoppingCartItem.Id != null)
         {
             var orderItem = shoppingCartItem.CreateOrderItemByProductId();
             orderItem.Order = order;
             order.OrderItems.Add(orderItem);
             var item = _shoppingCartItemRepository.GetByExpression(x => x.Id == shoppingCartItem.Id);
             if (item != null)
                 _shoppingCartItemRepository.Remove(item);
         }
     }
     order.User = user;
     order.Status = DictOrderStatus.创建;//先创建订单,付款需要用到订单号
     _orderRepository.Add(order);
     _repositoryContext.Commit();
     return order;
     //var shoppingCartItems=shoppingCart.Id
 }
Ejemplo 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;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建订单,涉及到的操作有2个:1. 把购物车中的项中购物车移除; 2.创建一个订单。
        /// 这两个操作必须同时完成或失败。
        /// </summary>
        /// <param name="user"></param>
        /// <param name="shoppingCart"></param>
        /// <returns></returns>
        public Order CreateOrder(User user, ShoppingCart shoppingCart)
        {
            var order = new Order();
            var shoppingCartItems =
                _shoppingCartItemRepository.GetAll(
                    new ExpressionSpecification<ShoppingCartItem>(s => s.ShoopingCart.Id == shoppingCart.Id));
            if (shoppingCartItems == null || !shoppingCartItems.Any())
                throw new InvalidOperationException("购物篮中没有任何物品");

            order.OrderItems = new List<OrderItem>();
            foreach (var shoppingCartItem in shoppingCartItems)
            {
                var orderItem = shoppingCartItem.ConvertToOrderItem();
                orderItem.Order = order;
                order.OrderItems.Add(orderItem);
                _shoppingCartItemRepository.Remove(shoppingCartItem);
            }
            order.User = user;
            order.Status = DictOrderStatus.创建;//先创建订单,付款需要用到订单号
            _orderRepository.Add(order);
            _repositoryContext.Commit();
            return order;
        }