示例#1
0
        //------------------------------------------------------------------------------------------------------------------------------------------+
        protected void ReviewAddBtn_Click(object sender, ImageClickEventArgs e)
        {
            if (Page.IsValid == true)
            {
                // Obtain ProductID from Page State
                int productID = Int32.Parse(Request["productID"]);

                // Obtain Rating number of RadioButtonList
                int rating = Int32.Parse(Rating.SelectedItem.Value);

                // Add Review to ReviewsDB.  HtmlEncode before entry
                using (CommerceEntities db = new CommerceEntities())
                {
                    try
                    {
                        ShoppingCart cartadd = new ShoppingCart();
                        Review newReview = new Review()
                        {
                            ProductID = productID,
                            Rating = rating,
                            CustomerName = HttpUtility.HtmlEncode(Name.Text),
                            CustomerEmail = HttpUtility.HtmlEncode(Email.Text),
                            Comments = HttpUtility.HtmlEncode(UserComment.Content)
                        };
                        db.Reviews.AddObject(newReview);
                        db.SaveChanges();
                    }
                    catch (Exception exp)
                    {
                        throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
                    }
                }
            Response.Redirect("ProductDetails.aspx?ProductID=" + productID);
            }
            Response.Redirect("ProductList.aspx");
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Reviews EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToReviews(Review review)
 {
     base.AddObject("Reviews", review);
 }
 /// <summary>
 /// Create a new Review object.
 /// </summary>
 /// <param name="reviewID">Initial value of the ReviewID property.</param>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="rating">Initial value of the Rating property.</param>
 public static Review CreateReview(global::System.Int32 reviewID, global::System.Int32 productID, global::System.Int32 rating)
 {
     Review review = new Review();
     review.ReviewID = reviewID;
     review.ProductID = productID;
     review.Rating = rating;
     return review;
 }