/// <summary> /// 通过指定的用户及其所拥有的购物篮实体,创建销售订单。 /// </summary> /// <param name="user">用户实体。</param> /// <param name="shoppingCart">购物篮实体。</param> /// <returns>销售订单实体。</returns> public SalesOrder CreateSalesOrder(User user, ShoppingCart shoppingCart) { var shoppingCartItems = shoppingCartItemRepository.FindItemsByCart(shoppingCart); if (shoppingCartItems == null || shoppingCartItems.Count() == 0) { throw new InvalidOperationException("购物篮中没有任何物品。"); } var salesOrder = new SalesOrder(); salesOrder.SalesLines = new List <SalesLine>(); foreach (var shoppingCartItem in shoppingCartItems) { 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> /// 将具有指定的全局唯一标识的购物篮项目从购物篮中删除。 /// </summary> /// <param name="shoppingCartItemID">需要删除的购物篮项目的全局唯一标识。</param> public void DeleteShoppingCartItem(Guid shoppingCartItemID) { var shoppingCartItem = shoppingCartItemRepository.GetByKey(shoppingCartItemID); shoppingCartItemRepository.Remove(shoppingCartItem); Context.Commit(); }
/// <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 = OrderStatus.Paid; _orderRepository.Add(order); _repositoryContext.Commit(); return(order); }
public void DeleteShoppingCartItem(Guid shoppingCartItemId) { var shoppingCartItem = _shoppingCartItemRepository.GetByKey(shoppingCartItemId); _shoppingCartItemRepository.Remove(shoppingCartItem); RepositorytContext.Commit(); }
public void Execute(int shopItemId, string cartId) { if (cartId is null) { throw new ArgumentNullException(nameof(cartId)); } _shoppingCartItemRepository.Remove(new ShoppingCartItem() { ShopItemId = shopItemId, ShoppingCartId = cartId }); }
public void Remove(Int64 id) { _shoppingCartItemRepository.Remove(id); }