Exemple #1
0
        public ActionResult Index(BasketRenderingViewModel model)
        {
            var cartServiceProvider = new CartServiceProvider();
            var cart = GetCart();

            foreach (var orderLine in model.OrderLines)
            {
                var newQuantity = orderLine.Quantity;

                if (model.RemoveOrderlineId == orderLine.OrderLineId)
                {
                    newQuantity = 0;
                }

                var bmw = cart.Lines.First(i => i.Product.ProductId == orderLine.Sku);

                bmw.Quantity = (uint)newQuantity;

                if (newQuantity > 0)
                {
                    var updateCartLinesRequest = new UpdateCartLinesRequest(cart, new Collection <CartLine> {
                        bmw
                    });
                    cartServiceProvider.UpdateCartLines(updateCartLinesRequest);
                }
                else
                {
                    var request = new RemoveCartLinesRequest(cart, cart.Lines.Where(l => l.Product.ProductId == bmw.Product.ProductId).ToArray());
                    cartServiceProvider.RemoveCartLines(request);
                }
            }

            return(Redirect("/Cart"));
        }
        public PipelineExecutionResult Execute(IPipelineArgs <UpdateLineItemRequest, UpdateLineItemResponse> subject)
        {
            if (subject.Request.Properties.ContainsKey("FromUCommerce"))
            {
                if (!(bool)subject.Request.Properties["FromUCommerce"])
                {
                    return(PipelineExecutionResult.Success);
                }
            }

            if (subject.Request.Quantity == 0)
            {
                var cart                = MappingLibrary.MapPurchaseOrderToCart(subject.Request.OrderLine.PurchaseOrder);
                var cartLine            = MappingLibrary.MapOrderLineToCartLine(subject.Request.OrderLine);
                var cartServiceProvider = new CartServiceProvider();

                var request = new RemoveCartLinesRequest(cart, new Collection <CartLine> {
                    cartLine
                });
                request.Properties["FromUCommerce"] = true;
                cartServiceProvider.RemoveCartLines(request);
            }
            return(PipelineExecutionResult.Success);
        }