Example #1
0
        private static List <MemberProduct> get(string query, Dictionary <string, object> parameters)
        {
            MemberProduct        item = null;
            Connection           cs   = new Connection();
            List <MemberProduct> list = new List <MemberProduct>();

            MySqlDataReader reader = cs.Select(query, parameters);

            while (reader.Read())
            {
                item = new MemberProduct();

                if (!reader.IsDBNull(reader.GetOrdinal("id")))
                {
                    item.id = reader.GetInt32(reader.GetOrdinal("id"));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("memberId")))
                {
                    item.memberId = reader.GetInt32(reader.GetOrdinal("memberId"));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("productId")))
                {
                    item.productId = reader.GetInt32(reader.GetOrdinal("producId"));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("date")))
                {
                    item.date = reader.GetDateTime(reader.GetOrdinal("date"));
                }

                if (!(reader["status"] == DBNull.Value))
                {
                    item.status = reader["status"].ToString().Trim();
                }

                list.Add(item);
            }

            cs.CloseConnection();
            return(list);
        }
Example #2
0
        public static int Add(MemberProduct m)
        {
            int    t     = 0;
            string query = @"INSERT INTO memberProduct (memberId, productId, date, status) " +
                           "VALUES (@memberId, @productId, NOW(), @status);";
            Connection cs = new Connection();
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("memberId", m.memberId);
            param.Add("productId", m.productId);
            param.Add("status", m.status);

            try
            {
                t = cs.Insert(query, param);
                //si insertion reussit
            }
            catch (MySqlException e) { }
            cs.CloseConnection();
            //si insertion echoue
            return(t);
        }