// 查询商品的所有评论 public static List <TMall.Models.ItemCommentModel> GetItemComments(int item_id) { string sql = $"select * from item_comment where item_id = {item_id}"; SqlDataReader data = SqlHelper.ExecuteTable(sql, null); List <Models.ItemCommentModel> comments = new List <Models.ItemCommentModel>(); if (data == null) { return(comments); } while (data.Read()) { Models.ItemCommentModel comment = new Models.ItemCommentModel { ItemCommentId = data.GetInt32(0), ItemId = data.GetInt32(1), Username = data.GetString(2), ItemCommentScore = data.GetInt32(3), ItemCommentText = data.GetString(4), ItemCommentTime = data.GetDateTime(5) }; comments.Add(comment); } data.Close(); return(comments); }
// 新增评论 public static bool AddItemComment(Models.ItemCommentModel itemComment) { SqlParameter[] sqlParameters = new SqlParameter[] { new SqlParameter("@A", itemComment.ItemId), new SqlParameter("@B", itemComment.Username), new SqlParameter("@C", itemComment.ItemCommentScore), new SqlParameter("@D", itemComment.ItemCommentText), new SqlParameter("@E", itemComment.ItemCommentTime) }; string sql = "insert into item_comment (item_id,username,item_comment_score,item_comment_text,item_comment_time) values(@A,@B,@C,@D,@E)"; return(1 == (int)SqlHelper.ExecuteNoQuery(sql, sqlParameters)); }