Exemplo n.º 1
0
        private static List <ProductComments> get(string query, Dictionary <string, object> parameters)
        {
            ProductComments        item = null;
            Connection             cs   = new Connection();
            List <ProductComments> list = new List <ProductComments>();

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

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

                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["comment"] == DBNull.Value))
                {
                    item.comment = reader["comment"].ToString().Trim();
                }

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

                list.Add(item);
            }

            cs.CloseConnection();
            return(list);
        }
Exemplo n.º 2
0
        public static int Add(ProductComments m)
        {
            int    t     = 0;
            string query = @"INSERT INTO productComments (productId, memberId, comment, date) " +
                           "VALUES (@productId, @memberId, @comment, NOW());";
            Connection cs = new Connection();
            Dictionary <string, object> param = new Dictionary <string, object>();

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

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