Exemple #1
0
        public async Task <ActionResult <UserManagerResponse> > UpdateItem(int productId, int updatedQuantity)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (User != null)
            {
                var item     = _ProductRepo.getProductById(productId);
                var cartItem = _CartRepo.getUserCart(userId).Where(c => c.ProductId == productId).FirstOrDefault();
                if (cartItem != null)
                {
                    var result = _CartRepo.UpdateCartItem(productId, userId, updatedQuantity, item.QuantityAvailable);
                    _CartRepo.saveContext();
                    return(result);
                }
            }
            return(new UserManagerResponse
            {
                IsSuccessful = false,
                Message = ""
            });
        }
 public IActionResult Put([FromQuery(Name = "u")] Guid userId, [FromBody] CartItem cartItem)
 {
     cartRepo.UpdateCartItem(userId, cartItem);
     return(new OkResult());
 }