Esempio n. 1
0
        public static Dinner Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM dinner WHERE id = (@searchId);";
            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);
            var      rdr       = cmd.ExecuteReader() as MySqlDataReader;
            int      DinnerId  = 0;
            string   food      = "";
            DateTime stampTime = new DateTime();
            float    sugar     = 0;
            float    carb      = 0;
            int      userId    = 0;

            while (rdr.Read())
            {
                DinnerId  = rdr.GetInt32(0);
                food      = rdr.GetString(1);
                stampTime = rdr.GetDateTime(2);
                sugar     = rdr.GetFloat(3);
                carb      = rdr.GetFloat(4);
                userId    = rdr.GetInt32(5);
            }
            Dinner newDinner = new Dinner(food, stampTime, sugar, carb, userId, DinnerId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newDinner);
        }
Esempio n. 2
0
        public List <Dinner> GetDinners()
        {
            List <Dinner> allLoginDinners = new List <Dinner> {
            };
            MySqlConnection conn          = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM dinner WHERE user_id = @user_id;";
            MySqlParameter userId = new MySqlParameter();

            userId.ParameterName = "@user_id";
            userId.Value         = this._id;
            cmd.Parameters.Add(userId);
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int      dinnerId  = rdr.GetInt32(0);
                string   food      = rdr.GetString(1);
                DateTime stampTime = rdr.GetDateTime(2);
                float    sugar     = rdr.GetFloat(3);
                float    carb      = rdr.GetFloat(4);
                int      user_id   = rdr.GetInt32(5);
                Dinner   newDinner = new Dinner(food, stampTime, sugar, carb, user_id);

                allLoginDinners.Add(newDinner);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allLoginDinners);
        }