public IActionResult GetActiveOrdersByCustomer(string userName)
        {
            try
            {
                List <Order>            orders       = _orderRepository.GetActiveOrder(userName);
                List <OrderWithDetails> returnOrders = new List <OrderWithDetails>();

                foreach (Order order in orders)
                {
                    if (order != null)
                    {
                        OrderWithDetails o = new OrderWithDetails();
                        o.order = order;
                        List <OrderDetail> orderDetail = _orderDetailsRepository.GetOrderLines(order.Id);
                        o.orderLines = orderDetail;
                        returnOrders.Add(o);
                    }
                }

                return(Ok(returnOrders));
            }
            catch (SqlException e)
            {
                _logger.LogError(e.ToString());
                return(Problem(e.ToString()));
            }
        }
        public IActionResult GetOrder(int id)
        {
            try
            {
                OrderWithDetails order = new OrderWithDetails();
                order.order = _orderRepository.GetOrder(id);

                if (order.order != null)
                {
                    var orderLines = _orderDetailsRepository.GetOrderLines(id);
                    order.orderLines = orderLines;
                    return(Ok(order));
                }
                return(NotFound("Order not exist"));
            }
            catch (Exception e)
            {
                _logger.LogError("Error in Order Controller: " + e.ToString());
                return(Problem(e.ToString()));
            }
        }
 public IActionResult AddOrder([FromBody] OrderWithDetails order)
 {
     try
     {
         if (order != null)
         {
             int orderId = _orderRepository.AddOrder(order.order);
             foreach (OrderDetail o in order.orderLines)
             {
                 o.OrderId = orderId;
                 _orderDetailsRepository.AddOrderLine(o);
             }
             return(Ok(orderId));
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         _logger.LogError("Error in Product controller: " + e.ToString());
         return(Problem(e.ToString()));
     }
 }