Ejemplo n.º 1
0
        //------------------------------------------------------------------------------------------------------------------------------------------+
        public void AddItem(string cartID, int productID, int quantity)
        {
            using (CommerceEntities db = new CommerceEntities())
            {
                try
                {
                    var myItem = (from c in db.ShoppingCarts where c.CartID == cartID && c.ProductID == productID select c).FirstOrDefault();
                    if (myItem == null)
                    {
                        ShoppingCart cartadd = new ShoppingCart();
                        cartadd.CartID = cartID;
                        cartadd.Quantity = quantity;
                        cartadd.ProductID = productID;
                        cartadd.DateCreated = DateTime.Now;
                        db.ShoppingCarts.AddObject(cartadd);
                    }
                    else
                    {
                        myItem.Quantity += quantity;
                    }

                    db.SaveChanges();
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Add Item to Cart - " + exp.Message.ToString(), exp);
                }
            }
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ShoppingCarts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToShoppingCarts(ShoppingCart shoppingCart)
 {
     base.AddObject("ShoppingCarts", shoppingCart);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create a new ShoppingCart object.
 /// </summary>
 /// <param name="recordID">Initial value of the RecordID property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 public static ShoppingCart CreateShoppingCart(global::System.Int32 recordID, global::System.Int32 quantity, global::System.Int32 productID, global::System.DateTime dateCreated)
 {
     ShoppingCart shoppingCart = new ShoppingCart();
     shoppingCart.RecordID = recordID;
     shoppingCart.Quantity = quantity;
     shoppingCart.ProductID = productID;
     shoppingCart.DateCreated = dateCreated;
     return shoppingCart;
 }