public OrderWithNames FindByOrderIdWithNames(string orderId)
        {
            StringBuilder sql = new StringBuilder(GetQueryWithNames());

            sql.AppendLine("WHERE o.orderId=@orderId");
            MySqlCommand command = new MySqlCommand(sql.ToString(), _context);

            command.Parameters.Add("@orderId", MySqlDbType.VarChar).Value = orderId;

            OrderWithNames order = null;

            using (IDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    if (order == null)
                    {
                        order = new OrderWithNames();
                        PopulateOrderWithNames(reader, order);
                    }
                    OrderItemWithNames newItem = new OrderItemWithNames();
                    PopulateOrderItemWithNames(reader, newItem);
                    order.Items.Add(newItem);
                }
            }

            return(order);
        }
        public List <OrderWithNames> FindAllWithNames()
        {
            List <OrderWithNames> orders  = new List <OrderWithNames>();
            MySqlCommand          command = new MySqlCommand(GetQueryWithNames(), _context);

            using (IDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    string orderId  = reader["orderId"].ToString();
                    string clientId = reader["clientId"].ToString();

                    OrderWithNames order = orders.Find(item => item.ClientId == clientId && item.OrderId == orderId);

                    if (order == null)
                    {
                        order = new OrderWithNames();
                        PopulateOrderWithNames(reader, order);
                        orders.Add(order);
                    }

                    OrderItemWithNames newItem = new OrderItemWithNames();
                    PopulateOrderItemWithNames(reader, newItem);
                    order.Items.Add(newItem);
                }
            }

            return(orders);
        }
 private void PopulateOrderItemWithNames(IDataReader reader, OrderItemWithNames order)
 {
     order.ProductId   = reader["productId"].ToString();
     order.ProductName = reader["productName"].ToString();
     order.Quantity    = int.Parse(reader["quantity"].ToString());
 }