示例#1
0
        public virtual async Task ChangeItemQuantityAsync(ChangeCartItemQty changeItemQty)
        {
            EnsureCartExists();

            var lineItem = Cart.Items.FirstOrDefault(i => i.Id == changeItemQty.LineItemId);

            if (lineItem != null)
            {
                await ChangeItemQuantityAsync(lineItem, changeItemQty.Quantity);
            }
        }
        public async Task <ActionResult> ChangeCartItem([FromBody] ChangeCartItemQty changeQty)
        {
            EnsureCartExists();

            //Need lock to prevent concurrent access to same cart
            using (await AsyncLock.GetLockByKey(WorkContext.CurrentCart.Value.GetCacheKey()).LockAsync())
            {
                var cartBuilder = await LoadOrCreateCartAsync();

                await cartBuilder.ChangeItemQuantityAsync(changeQty);

                await cartBuilder.SaveAsync();
            }
            return(Ok());
        }
        public async Task <ActionResult> ChangeCartItem([FromBody] ChangeCartItemQty changeQty)
        {
            EnsureCartExists();

            //Need lock to prevent concurrent access to same cart
            using (await AsyncLock.GetLockByKey(WorkContext.CurrentCart.Value.GetCacheKey()).LockAsync())
            {
                var cartBuilder = await LoadOrCreateCartAsync();

                var lineItem = cartBuilder.Cart.Items.FirstOrDefault(i => i.Id == changeQty.LineItemId);
                if (lineItem != null)
                {
                    await cartBuilder.ChangeItemQuantityAsync(changeQty.LineItemId, changeQty.Quantity);

                    await cartBuilder.SaveAsync();
                }
            }
            return(Ok());
        }
示例#4
0
        public override Task ChangeItemQuantityAsync(ChangeCartItemQty changeItemQty)
        {
            EnsureCartExists();

            var configuredGroup = Cart.ConfiguredGroups?.FirstOrDefault(x => x.Id.Equals(changeItemQty.LineItemId, StringComparison.InvariantCulture));

            if (configuredGroup != null)
            {
                configuredGroup.Quantity = changeItemQty.Quantity;

                var groupItems = Cart.Items.Where(x => !string.IsNullOrEmpty(x.ConfiguredGroupId) &&
                                                  x.ConfiguredGroupId.Equals(configuredGroup.Id, StringComparison.InvariantCulture)).ToArray();

                foreach (var lineItem in groupItems)
                {
                    lineItem.Quantity = changeItemQty.Quantity;
                }
            }

            return(base.ChangeItemQuantityAsync(changeItemQty));
        }
        public async Task <ActionResult> ChangeListItem(string listName, string type, [FromBody] ChangeCartItemQty changeQty)
        {
            var unescapedListName = Uri.UnescapeDataString(listName);

            //Need lock to prevent concurrent access to same list
            using (await AsyncLock.GetLockByKey(GetAsyncListKey(WorkContext, unescapedListName, type)).LockAsync())
            {
                var cartBuilder = await LoadOrCreateCartAsync(unescapedListName, type);

                var lineItem = cartBuilder.Cart.Items.FirstOrDefault(i => i.Id == changeQty.LineItemId);
                if (lineItem != null)
                {
                    await cartBuilder.ChangeItemQuantityAsync(changeQty.LineItemId, changeQty.Quantity);

                    await cartBuilder.SaveAsync();
                }
            }
            return(Ok());
        }