/// <summary> /// 初始化一个<c>ShoppingCartItem</c>类型的实例。 /// </summary> /// <param name="product">属于该购物篮项目的笔记本电脑商品实体。</param> /// <param name="shoppingCart">拥有该购物篮项目的购物篮实体。</param> public ShoppingCartItem(Product product, ShoppingCart shoppingCart, int quantity) { this.quantity = quantity; this.product = product; this.shoppingCart = shoppingCart; }
/// <summary> /// 为当前用户创建购物篮。 /// </summary> /// <returns>已创建的购物篮实例,该购物篮为当前用户所用。</returns> public ShoppingCart CreateShoppingCart() { ShoppingCart shoppingCart = new ShoppingCart(); shoppingCart.User = this; return shoppingCart; }
/// <summary> /// 通过指定的用户及其所拥有的购物篮实体,创建销售订单。 /// </summary> /// <param name="user">用户实体。</param> /// <param name="shoppingCart">购物篮实体。</param> /// <returns>销售订单实体。</returns> public SalesOrder CreateSalesOrder(User user, ShoppingCart shoppingCart) { var shoppingCartItems = _shoppingCartItemRepository.FindItemsByCart(shoppingCart); var cartItems = shoppingCartItems as IList<ShoppingCartItem> ?? shoppingCartItems.ToList(); if (shoppingCartItems == null || !cartItems.Any()) throw new InvalidOperationException("购物篮中没有任何物品。"); var salesOrder = new SalesOrder {SalesLines = new List<SalesLine>()}; foreach (var shoppingCartItem in cartItems) { var salesLine = shoppingCartItem.ConvertToSalesLine(); salesLine.SalesOrder = salesOrder; salesOrder.SalesLines.Add(salesLine); _shoppingCartItemRepository.Remove(shoppingCartItem); } salesOrder.User = user; salesOrder.Status = SalesOrderStatus.Paid; _salesOrderRepository.Add(salesOrder); _repositoryContext.Commit(); return salesOrder; }
/// <summary> /// 初始化一个<c>ShoppingCartItem</c>类型的实例。 /// </summary> /// <param name="product">属于该购物篮项目的笔记本电脑商品实体。</param> /// <param name="shoppingCart">拥有该购物篮项目的购物篮实体。</param> /// <param name="quantity">拥有该购物篮项目的购物篮数量实体。</param> public ShoppingCartItem(Product product, ShoppingCart shoppingCart, int quantity) { _quantity = quantity; _product = product; _shoppingCart = shoppingCart; }
/// <summary> /// 为当前用户创建购物篮。 /// </summary> /// <returns>已创建的购物篮实例,该购物篮为当前用户所用。</returns> public ShoppingCart CreateShoppingCart() { var shoppingCart = new ShoppingCart {User = this}; return shoppingCart; }