public void btnRefer_Click(object sender, EventArgs e) { if (this.ValidateConvert()) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (RepeaterItem item in this.orderItems.Items) { HtmlTextArea area = item.FindControl("txtcontent") as HtmlTextArea; HtmlInputHidden hidden = item.FindControl("hdproductId") as HtmlInputHidden; if (!string.IsNullOrEmpty(area.Value.Trim()) && !string.IsNullOrEmpty(hidden.Value.Trim())) { dictionary.Add(hidden.Value, area.Value); } } if (dictionary.Count <= 0) { this.ShowMessage("请输入评价内容呀!", false); } else { string msg = ""; foreach (KeyValuePair <string, string> pair in dictionary) { int productId = Convert.ToInt32(pair.Key.Split(new char[] { '&' })[0].ToString()); string str2 = pair.Value; ProductReviewInfo target = new ProductReviewInfo(); target.ReviewDate = DateTime.Now; target.ProductId = productId; target.UserId = HiContext.Current.User.UserId; target.UserName = HiContext.Current.User.Username; target.UserEmail = HiContext.Current.User.Email; target.ReviewText = str2; ValidationResults results = Hishop.Components.Validation.Validation.Validate <ProductReviewInfo>(target, new string[] { "Refer" }); msg = string.Empty; if (!results.IsValid) { foreach (ValidationResult result in (IEnumerable <ValidationResult>)results) { msg = msg + Formatter.FormatErrorMessage(result.Message); } break; } if (!ProductProcessor.ProductExists(productId)) { msg = "您要评论的商品已经不存在"; break; } int buyNum = 0; int reviewNum = 0; ProductBrowser.LoadProductReview(productId, out buyNum, out reviewNum); if (buyNum == 0) { msg = "您没有购买此商品,因此不能进行评论"; break; } if (reviewNum >= buyNum) { msg = "您已经对此商品进行了评论,请再次购买后方能再进行评论"; break; } if (!ProductProcessor.InsertProductReview(target)) { msg = "评论失败,请重试"; break; } } if (msg != "") { this.ShowMessage(msg, false); } else { this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "success", string.Format("<script>alert(\"{0}\");window.location.href=\"{1}\"</script>", "评论成功", Globals.GetSiteUrls().UrlData.FormatUrl("user_UserProductReviews"))); } } } }
public void btnRefer_Click(object sender, System.EventArgs e) { if (this.ValidateConvert()) { System.Collections.Generic.Dictionary <string, string> dictionary = new System.Collections.Generic.Dictionary <string, string>(); foreach (System.Web.UI.WebControls.RepeaterItem repeaterItem in this.orderItems.Items) { System.Web.UI.HtmlControls.HtmlTextArea htmlTextArea = repeaterItem.FindControl("txtcontent") as System.Web.UI.HtmlControls.HtmlTextArea; System.Web.UI.HtmlControls.HtmlInputHidden htmlInputHidden = repeaterItem.FindControl("hdproductId") as System.Web.UI.HtmlControls.HtmlInputHidden; if (!string.IsNullOrEmpty(htmlTextArea.Value.Trim()) && !string.IsNullOrEmpty(htmlInputHidden.Value.Trim())) { dictionary.Add(htmlInputHidden.Value, htmlTextArea.Value); } } if (dictionary.Count <= 0) { this.ShowMessage("请输入评价内容呀!", false); } else { string text = ""; foreach (System.Collections.Generic.KeyValuePair <string, string> current in dictionary) { int productId = System.Convert.ToInt32(current.Key.Split(new char[] { '&' })[0].ToString()); string value = current.Value; ProductReviewInfo productReviewInfo = new ProductReviewInfo(); productReviewInfo.ReviewDate = System.DateTime.Now; productReviewInfo.ProductId = productId; productReviewInfo.UserId = HiContext.Current.User.UserId; productReviewInfo.UserName = HiContext.Current.User.Username; productReviewInfo.UserEmail = HiContext.Current.User.Email; productReviewInfo.ReviewText = value; ValidationResults validationResults = Validation.Validate <ProductReviewInfo>(productReviewInfo, new string[] { "Refer" }); text = string.Empty; if (validationResults.IsValid) { if (ProductProcessor.ProductExists(productId)) { int num = 0; int num2 = 0; ProductBrowser.LoadProductReview(productId, out num, out num2); if (num == 0) { text = "您没有购买此商品,因此不能进行评论"; break; } if (num2 >= num) { text = "您已经对此商品进行了评论,请再次购买后方能再进行评论"; break; } if (ProductProcessor.InsertProductReview(productReviewInfo)) { continue; } text = "评论失败,请重试"; break; } } else { using (System.Collections.Generic.IEnumerator <ValidationResult> enumerator3 = ((System.Collections.Generic.IEnumerable <ValidationResult>)validationResults).GetEnumerator()) { while (enumerator3.MoveNext()) { ValidationResult current2 = enumerator3.Current; text += Formatter.FormatErrorMessage(current2.Message); } break; } } text = "您要评论的商品已经不存在"; break; } if (text != "") { this.ShowMessage(text, false); } else { this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "success", string.Format("<script>alert(\"{0}\");window.location.href=\"{1}\"</script>", "评论成功", Globals.GetSiteUrls().UrlData.FormatUrl("user_UserProductReviews"))); } } } }