public async Task <IActionResult> Delete(string orderNumber, int id)
        {
            try
            {
                var orderItem = await _repository.GetOrderItemByOrderNumberAsync(orderNumber, id);

                if (orderItem == null)
                {
                    return(NotFound("Failed to find the orderItem to delete"));
                }

                _repository.Delete(orderItem);

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Failed to delete orderItem"));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to get OrderItem"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(string orderNumber)
        {
            try
            {
                var oldOrder = await _repository.GetOrderAsync(orderNumber);

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

                _repository.Delete(oldOrder);
                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest("Failed to delete order"));
        }