public void DeleteCartItem(long cartItemId, long productId, int quantity, long userId) { var cartItem = new CartItemUpdateEntity() { CartItemId = cartItemId, ProductId = productId, Quantity = quantity, UserId = userId }; _client.Delete(EndpointsResources.RemoveCartItem, cartItem); }
public ShoppingCartResponse UpdateCartItem(long cartItemId, long productId, int newQuantity, long userId) { var cartItem = new CartItemUpdateEntity() { CartItemId = cartItemId, ProductId = productId, Quantity = newQuantity, UserId = userId }; return(_client.Put <ShoppingCartResponse>(EndpointsResources.UpdateCartItem, cartItem)); }
/// <summary> /// Update the product quantity for the cart item that will be deleted /// </summary> /// <param name="cartItem"></param> public override void Process(CartItemUpdateEntity cartItem) { var product = _unitOfWork.RepositoryFactory <Product>().Get(p => p.Id == cartItem.ProductId); product.AvailabilityCount += cartItem.Quantity; _unitOfWork.RepositoryFactory <Product>().Update(product); base.Process(cartItem); }
/// <summary> /// Updates the cartItem /// </summary> /// <param name="cartItemUpdate"></param> /// <returns></returns> public override ShoppingCartResponse Process(CartItemUpdateEntity cartItemUpdate) { ExistingCartItem.Product.AvailabilityCount += ExistingCartItem.Quantity - cartItemUpdate.Quantity; ExistingCartItem.Quantity = cartItemUpdate.Quantity; _unitOfWork.RepositoryFactory <CartItem>().Update(ExistingCartItem); _unitOfWork.Save(); return(MapperHelper.Map(ExistingCartItem.ShoppingCart)); }
/// <summary> /// Process updating product availability /// </summary> /// <remarks> /// There are two scenarios here: /// 1. If the updated quantity will be updated with more quantity, then checks if the difference is exsits for this /// product. /// 2. otherwise proceed to the next step /// </remarks> /// <param name="cartItemUpdate"></param> /// <exception cref="ProductNotAvailableException"></exception> /// <returns></returns> public override ShoppingCartResponse Process(CartItemUpdateEntity cartItemUpdate) { ExistingCartItem = _unitOfWork.RepositoryFactory <CartItem>().Get(c => c.Id == cartItemUpdate.CartItemId); if (cartItemUpdate.Quantity > ExistingCartItem.Quantity) { var quantityDiff = cartItemUpdate.Quantity - ExistingCartItem.Quantity; var product = GetProduct(cartItemUpdate.ProductId); var isAvailable = IsProductAvailable(product, quantityDiff); if (!isAvailable) { throw new ProductNotAvailableException(string.Format(ErrorMessages.ProductNotAvailable, quantityDiff, cartItemUpdate.ProductId)); } } return(base.Process(cartItemUpdate)); }
/// <summary> /// Process Delete cart item /// </summary> /// <remarks> /// There is two scenarios for deleting cart item /// 1. if there is only one cart item in shopping cart, then the entire shopping cart will be deleted /// 2. if there more than one cart item in shopping cart, then the cart item only will be deleted /// </remarks> /// <param name="cartItem"></param> public override void Process(CartItemUpdateEntity cartItem) { var currentShoppingCartItems = _unitOfWork.RepositoryFactory <ShoppingCart>().Get(sc => sc.UserId == cartItem.UserId && sc.ShoppingCartStatu.Status == CartStatus.InProgress.ToString(), false) .CartItems; if (currentShoppingCartItems.Count > 1) { _unitOfWork.RepositoryFactory <CartItem>().Delete(ci => ci.Id == cartItem.CartItemId); } else { _unitOfWork.RepositoryFactory <ShoppingCart>().Delete(sc => sc.UserId == cartItem.UserId && sc.ShoppingCartStatu.Status == CartStatus.InProgress.ToString()); } _unitOfWork.RepositoryFactory <CartItem>().DeAttach(currentShoppingCartItems); _unitOfWork.Save(); base.Process(cartItem); }
public HttpResponseMessage DeleteCartItem(CartItemUpdateEntity cartItemUpdate) { _deleteItemProcessor.Process(cartItemUpdate); return(new HttpResponseMessage(HttpStatusCode.Accepted)); }
public ShoppingCartResponse ModifyCartItem(CartItemUpdateEntity cartItemUpdate) { return(_updateItemProcessor.Process(cartItemUpdate)); }
/// <summary> /// Process next steps if any /// </summary> /// <param name="cartItemUpdate"></param> /// <returns></returns> public virtual ShoppingCartResponse Process(CartItemUpdateEntity cartItemUpdate) { return(_nextStep?.Process(cartItemUpdate)); }
/// <summary> /// Process next step if any /// </summary> /// <param name="cartItem"></param> public virtual void Process(CartItemUpdateEntity cartItem) { _nextStep?.Process(cartItem); }