Exemplo n.º 1
0
        public async Task <IActionResult> UpdateQuantity([FromBody] CartQuantityUpdate model)
        {
            ModificaLinea(GetIP(), GetSession(), model.CartItemId, model.Quantity);
            //var currentUser = await _workContext.GetCurrentUser();
            //var cart = await _cartService.GetActiveCart(currentUser.Id);

            //if (cart == null)
            //{
            //    return NotFound();
            //}

            //if (cart.LockedOnCheckout)
            //{
            //    return CreateCartLockedResult();
            //}

            //var cartItem = _cartItemRepository.Query().Include(x => x.Product).FirstOrDefault(x => x.Id == model.CartItemId && x.Cart.CreatedById == currentUser.Id);
            //if (cartItem == null)
            //{
            //    return NotFound();
            //}

            //if(model.Quantity > cartItem.Quantity) // always allow user to descrease the quality
            //{
            //    if (cartItem.Product.StockTrackingIsEnabled && cartItem.Product.StockQuantity < model.Quantity)
            //    {
            //        return Ok(new { Error = true, Message = $"There are only {cartItem.Product.StockQuantity} items available for {cartItem.Product.Name}" });
            //    }
            //}

            //cartItem.Quantity = model.Quantity;
            //_cartItemRepository.SaveChanges();

            return(await List());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateQuantity([FromBody] CartQuantityUpdate model)
        {
            var currentUser = await _workContext.GetCurrentUser();

            var cart = await _cartService.GetActiveCart(currentUser.Id);

            if (cart == null)
            {
                return(NotFound());
            }

            if (cart.LockedOnCheckout)
            {
                return(CreateCartLockedResult());
            }

            var cartItem = _cartItemRepository.Query().FirstOrDefault(x => x.Id == model.CartItemId && x.Cart.CreatedById == currentUser.Id);

            if (cartItem == null)
            {
                return(NotFound());
            }

            cartItem.Quantity = model.Quantity;
            _cartItemRepository.SaveChanges();

            return(await List());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateQuantity([FromBody] CartQuantityUpdate model)
        {
            var cartItem = _cartItemRepository.Query().FirstOrDefault(x => x.Id == model.CartItemId);

            cartItem.Quantity = model.Quantity;

            _cartItemRepository.SaveChange();

            return(await List());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateQuantity(long itemId, [FromBody] CartQuantityUpdate model)
        {
            var currentUser = await _workContext.GetCurrentUser();

            var cartItem = _cartItemRepository.Query().FirstOrDefault(x => x.Id == itemId && x.Cart.CreatedById == currentUser.Id);

            if (cartItem == null)
            {
                return(NotFound());
            }

            cartItem.Quantity = model.Quantity;
            _cartItemRepository.SaveChanges();

            return(Accepted());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> UpdateQuantity([FromBody] CartQuantityUpdate model)
        {
            if (model.Quantity <= 0)
            {
                return(Ok(new { Error = true, Message = _localizer["The quantity must be larger than zero"].Value }));
            }
            var currentUser = await _workContext.GetCurrentUser();

            var cart = await _cartService.GetActiveCart(currentUser.Id);

            if (cart == null)
            {
                return(NotFound());
            }

            if (cart.LockedOnCheckout)
            {
                return(CreateCartLockedResult());
            }

            var cartItem = _cartItemRepository.Query().Include(x => x.Product).FirstOrDefault(x => x.Id == model.CartItemId && x.Cart.CreatedById == currentUser.Id);

            if (cartItem == null)
            {
                return(NotFound());
            }

            if (model.Quantity > cartItem.Quantity) // always allow user to descrease the quality
            {
                if (cartItem.Product.StockTrackingIsEnabled && cartItem.Product.StockQuantity < model.Quantity)
                {
                    return(Ok(new { Error = true, Message = _localizer["There are only {0} items available for {1}.", cartItem.Product.StockQuantity, cartItem.Product.Name].Value }));
                }
            }

            cartItem.Quantity = model.Quantity;
            _cartItemRepository.SaveChanges();

            return(await List());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> UpdateQuantity([FromBody] CartQuantityUpdate model)
        {
            var currentUser = await _workContext.GetCurrentUser();

            var cart = await _cartService.GetActiveCart(currentUser.Id);

            if (cart == null)
            {
                return(NotFound());
            }

            if (cart.LockedOnCheckout)
            {
                return(CreateCartLockedResult());
            }

            var cartItem = _cartItemRepository.Query().Include(x => x.Product).FirstOrDefault(x => x.Id == model.CartItemId && x.Cart.CreatedById == currentUser.Id);

            if (cartItem == null)
            {
                return(NotFound());
            }

            if (model.Quantity > cartItem.Quantity) // always allow user to descrease the quality
            {
                if (cartItem.Product.StockTrackingIsEnabled && cartItem.Product.StockQuantity < model.Quantity)
                {
                    return(Ok(new { Error = true, Message = $"تنها {cartItem.Product.StockQuantity} عدد از کالای {cartItem.Product.Name} موجود است" }));
                }
            }

            cartItem.Quantity = model.Quantity;
            _cartItemRepository.SaveChanges();

            return(await List());
        }