Esempio n. 1
0
        public ActionResult UpdateProductQuantity(Int32 basketPartId, Guid orderSubsetId, Guid productId, Int32 quantity)
        {
            String message = null;

            if (quantity >= 0)
            {
                BasketEntryResult result = null;

                if (
                    this._webStoreServices.UsingClient(
                        c => result = c.BasketClient.UpdateProductQuantity(
                            this._webStoreServices.CurrentUserName,
                            this._webStoreServices.BasketName,
                            orderSubsetId,
                            productId,
                            quantity
                            ).FirstOrDefault(r => r.ProductId == productId)
                        ) != null
                    )
                {
                    message = this._localizer("An unexpected error has occured").ToString();
                }
                else if (result != null)
                {
                    this._basketEventHandlers.Trigger(h => h.ProductQuantityUpdated(result));
                }
            }
            return(this.GetBasket(basketPartId, null, message));
        }
Esempio n. 2
0
        public JsonResult AddToBasket(Guid productId, Int32 quantity)
        {
            Boolean success = false;

            Int32 addedQuantity = 0;
            Int32 totalQuantity = 0;

            if (quantity > 0)
            {
                Exception exception = this._webStoreServices.UsingClient(
                    c =>
                {
                    Int32 initialQuantity = c.BasketClient.GetBaskets(this._webStoreServices.CurrentUserName, new[] { this._webStoreServices.BasketName })
                                            .SelectMany(b => b.OrderSubsets)
                                            .SelectMany(os => os.LineItems)
                                            .Where(li => li.ProductId == productId)
                                            .Sum(li => li.Quantity);

                    BasketEntryResult result = c.BasketClient.AddProductsToBasket(
                        this._webStoreServices.CurrentUserName,
                        this._webStoreServices.IsAnonymous,
                        this._webStoreServices.BasketName,
                        productId,
                        quantity,
                        this._webStoreServices.CurrentCurrencyId,
                        this._webStoreServices.CurrentCultureId,
                        new Location
                    {
                        RegionId  = this._webStoreServices.CurrentRegionId,
                        CountryId = this._webStoreServices.CurrentCountryId
                    }
                        ).FirstOrDefault(ber => ber.ProductId == productId);

                    if (result == null)
                    {
                        success = false;
                    }
                    else
                    {
                        if (
                            result.State != BasketEntryState.Dispatched &&
                            result.State != BasketEntryState.PartiallyDispatched
                            )
                        {
                            success = true;
                        }
                        else
                        {
                            success       = true;
                            totalQuantity = result.Quantity;
                            addedQuantity = totalQuantity - initialQuantity;
                        }

                        this._basketEventHandlers.Trigger(h => h.ProductAddedToBasket(result));
                    }
                }
                    );

                if (exception != null)
                {
                    success = false;
                }
            }

            return(this.Json(new { success = success, totalQuantity = totalQuantity, addedQuantity = addedQuantity }));
        }