예제 #1
0
        public async Task <IActionResult> Post([FromBody] CartItemViewModel cartItem)
        {
            try
            {
                var newCartItem = Mapper.Map <CartItem>(cartItem);
                _repository.AddCartItem(newCartItem);


                if (await _repository.SaveChangesAsync())
                {
                    return(Created($"api/cart/{cartItem.CartItemId}", Mapper.Map <CartItemViewModel>(newCartItem)));
                }
            }

            catch (Exception ex)
            {
                _logger.LogError("Failed to save cart item {0}", ex);
            }
            return(BadRequest("Failed to save cart item"));
        }