コード例 #1
0
        /// <summary>
        /// Get list of products review from database
        /// </summary>
        /// <param name="whereString">sql string contain 'where' params. Ex: "name LIKE '%name%'"</param>
        /// <returns>List of ProductReview objects</returns>
        public List <IProductReview> GetProductsReview(string whereString = "")
        {
            List <IProductReview> list    = new List <IProductReview>();
            DBAdapter             adapter = new DBAdapter();
            MySqlDataReader       products;

            try
            {
                adapter.OpenConnection();
                if (whereString == "")
                {
                    products = adapter.GetSelectReader("oc_review", join: adapter.GetJoinedTableString("oc_product_description", "LEFT", "product_id"));
                }
                else
                {
                    products = adapter.GetSelectReader("oc_review", where : whereString, join: adapter.GetJoinedTableString("oc_product_description", "LEFT", "product_id"));
                }
                while (products.Read())
                {
                    list.Add(ProductReview.Get()
                             .SetProductName(products["name"].ToString())
                             .SetReviewerName(products["author"].ToString())
                             .SetReviewText(products["text"].ToString())
                             .SetRating((Int32.Parse(products["raiting"].ToString())).ToRating())
                             .SetDate(products["date_added"].ToString())
                             .Build());
                }
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                adapter.CloseConnection();
            }
            return(list);
        }