Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 private void PopulateOrderWithNames(IDataReader reader, OrderWithNames order)
 {
     order.ClientId   = reader["clientId"].ToString();
     order.ClientName = reader["clientName"].ToString();
     order.OrderId    = reader["orderId"].ToString();
     order.OrderDate  = System.DateTime.Parse(reader["orderDate"].ToString()).Date;
     order.Items      = new List <OrderItemWithNames>();
 }