public Table query(MySqlCommand command)
        {
            /*
             * the query function (this function will be used to execute queries)
             * the results of the query will be returned in a list containing fieldList's (a list containing fields, for more info see the field class)
             */

            //this variable will be used to return the results of the query that was executed
            Table m_result = new Table();

            //the connection is opened (if it was closed)
            if (con.State == System.Data.ConnectionState.Closed)
            {
                con.Open();
            }

            //this variable will be used to read the results of the query that was executed
            MySqlDataReader m_reader = command.ExecuteReader();

            //this is a string array that will hold all of the column names
            string[] m_columns = Enumerable.Range(0, m_reader.FieldCount).Select(m_reader.GetName).ToArray();



            //while there are records to read this loop will keep running
            while (m_reader.Read())
            {
                //this variable will hold all the data of a record
                Record m_values = new Record();

                //the code within this loop will be executed for each column in the string array
                foreach (string m_column in m_columns)
                {
                    //an object is created with the column name and value of the current field
                    Field m_field = new Field {
                        key = m_column, value = m_reader[m_column].ToString()
                    };

                    //the object will be added to the object that holds the fields for the current record
                    m_values.Add(m_field);
                }

                //the object with the record will be added to the object that holds all the records
                m_result.Add(m_values);
            }
            //the connection is closed (if it was open)
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }

            //the object with all the records is used as the return value
            return(m_result);
        }
Exemple #2
0
 public LayerResult <OrderModel> MakeOrder(OrderModel order)
 {
     order.Id = Table.Max(x => x.Id);
     Table.Add(order);
     return(new LayerResult <OrderModel>(order));
 }