/// <summary> /// 将具有指定的全局唯一标识的购物篮项目从购物篮中删除。 /// </summary> /// <param name="shoppingCartItemID">需要删除的购物篮项目的全局唯一标识。</param> public void DeleteShoppingCartItem(Guid shoppingCartItemID) { var shoppingCartItem = shoppingCartItemRepository.Get(shoppingCartItemID); shoppingCartItemRepository.Delete(shoppingCartItem); Context.Commit(); }
public bool DeleteShoppingCartItemByName(string name) { ShoppingCartItem dbItem = _shoppingCartItemRepository.GetByName(name); if (dbItem == null) { return(false); } _shoppingCartItemRepository.Delete(dbItem); return(true); }
public async Task DeleteProductAsync(string customerId, long productId, int quantity) { await _unitOfWork.RunInTrunsaction(async() => { var cart = await _shoppingCartRepository.GetByCustomerId(customerId, includeItems: true); if (cart == null) { return; } cart.LatestUpdatedOn = DateTimeOffset.UtcNow; await _shoppingCartRepository.Update(cart); var cartItem = cart.ShoppingCartItems.FirstOrDefault(x => x.ProductId == productId); if (cartItem == null) { return; } if (cartItem.Quantity > quantity) { cartItem.Quantity -= quantity; await _shoppingCartItemRepository.Update(cartItem); } else { await _shoppingCartItemRepository.Delete(cartItem); } }); }
public ActionResult DeleteConfirmed(int id) { shoppingcartitemRepository.Delete(id); shoppingcartitemRepository.Save(); return(RedirectToAction("Index")); }
/// <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.Delete(shoppingCartItem); } salesOrder.User = user; salesOrder.Status = SalesOrderStatus.Paid; salesOrderRepository.Insert(salesOrder); repositoryContext.Commit(); return(salesOrder); }
public void RemoveFromCart(ShoppingCartItem entity) { if (entity.Quantity > 1) { entity.Quantity--; _shoppingCartItemRepository.Update(entity); } else { _shoppingCartItemRepository.Delete(entity); } }
public ShoppingCart UpdateItem(int shoppingCartItemId, int quantity, int userId) { if (quantity < 0) { throw new Exception("Quantity cannot be less than zero"); } ShoppingCartItem item = shoppingCartItemRepository.Get(shoppingCartItemId); if (item == null) { throw new Exception($"Item with id {shoppingCartItemId} was not found"); } if (quantity == 0) { shoppingCartItemRepository.Delete(item.Id); } else { item.Quantity = quantity; shoppingCartItemRepository.Update(item); } return(GetCart(item.ShoppingCartId)); }
public Order CreateOrder(User user, ShoppingCart shoppingCart) { var order = new Order(); var shoppingCartItems = _shoppingCartItemRepository.GetAllList(s => s.ShoppingCart.Id == shoppingCart.Id); if (shoppingCartItems == null || !shoppingCartItems.Any()) { throw new InvalidOperationException("Shopping Cart have not any item"); } order.OrderItems = new List <OrderItem>(); foreach (var shoppingCartItem in shoppingCartItems) { var orderItem = shoppingCartItem.ConvertToOrderItem(); orderItem.Order = order; order.OrderItems.Add(orderItem); _shoppingCartItemRepository.Delete(shoppingCartItem); } order.User = user; order.Status = OrderStatus.Paid; _orderRepository.Insert(order); return(order); }
public Order Create(int shoppingCartId, int userId, OrderPaymentMethod paymentMethod, string address1, string address2, string address3, string city, string state, string postalCode, string emailAddress) { var cart = _shoppingCartRepository.Get(shoppingCartId); if (cart == null) { throw new Exception("Shopping cart not found."); } if (userId != cart.UserId) { throw new Exception("Shopping cart not found."); } var cartItems = _shoppingCartItemRepository.Fetch(shoppingCartId); if (cartItems == null || !cartItems.Any()) { throw new Exception("No items found in shopping cart."); } Order newOrder = new Order() { Items = new List <OrderItem>(), CreateDate = DateTime.UtcNow, PaymentMethod = paymentMethod, Status = OrderStatus.Placed, UserId = cart.UserId, Address1 = address1, Address2 = address2, Address3 = address3, City = city, State = state, PostalCode = postalCode, EmailAddress = emailAddress }; foreach (var item in cartItems) { OrderItem orderItem = new OrderItem() { ProductId = item.ProductId, Quantity = item.Quantity, Price = item.Price }; newOrder.Items.Add(orderItem); } _orderRepository.Add(newOrder); foreach (var orderItem in newOrder.Items) { orderItem.OrderId = newOrder.Id; _orderItemRepository.Add(orderItem); } foreach (var cartItem in cartItems) { _shoppingCartItemRepository.Delete(cartItem.Id); } return(newOrder); }