Example #1
0
        public async Task <IActionResult> Update(OrderItem item)
        {
            try
            {
                var itemAux = (OrderItem)await _repo.GetOrderItemAsync(item.OrderId, item.ProductId);

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

                itemAux.Price    = item.Price;
                itemAux.Quantity = item.Quantity;

                _repo.Update(itemAux);

                if (await _repo.SaveChangesAsync())
                {
                    return(Ok(itemAux));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(
                           StatusCodes.Status500InternalServerError,
                           "Erro ao atualizar o item do pedido\n"
                           + ex.InnerException));
            }

            return(BadRequest());
        }
        public async void Test_GetOrderItemAsync()
        {
            int orderItemId = 3;
            int orderId     = 1;
            var orderItem   = await _orderItemRepository.GetOrderItemAsync(orderId, orderItemId);

            string expectedName = "Item 3";

            Assert.Equal(expectedName, orderItem.Name);
            Assert.Equal(orderId, orderItem.OrderId);
        }