public async Task <ActionResult <UserManagerResponse> > addToUserCart([FromBody] AddProductToCart product) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (User != null) { int AvailableQuantity = _ProductRepo.getProductQuantity(product.ProductId); if (AvailableQuantity >= product.InCartQuantity) { var cartItem = _mapper.Map <CartItem>(product); var info = _ProductRepo.getProductById(cartItem.ProductId); cartItem.UserId = userId; cartItem.ItemName = info.Name; cartItem.Image = info.ImagePathsArr[0]; cartItem.UnitePrice = info.Price; var result = _CartRepo.AddToCartQuantity(cartItem, AvailableQuantity); if (!result.IsSuccessful) { await _CartRepo.addToUserCart(cartItem); _CartRepo.saveContext(); return(new UserManagerResponse { IsSuccessful = true, Message = "Added to cart" }); } _CartRepo.saveContext(); return(result); } return(new UserManagerResponse { IsSuccessful = false, Message = "Desired Quantity is over the available" }); } return(new UserManagerResponse { IsSuccessful = false, Message = "Process not successful" }); }