Exemplo n.º 1
0
    //When the user clicks checkout with Paypal, add the cart to the database as an order and transfer to Paypal for payment processing
    protected void btnCheckoutWithPaypal_Click(object sender, EventArgs e)
    {
        if (Session["ShoppingCart"] != null)
        {
            Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];

            if (c.IfHasItems) // only transfer to paypal if the cart has something in it
            {
                bool ordercreated = c.CreateOrder(User.Identity.Name);

                //If the order was successfully created in the database, redirect the user to the Paypal checkout page.
                if (ordercreated)
                {
                    Response.Redirect("PaymentPaypal.aspx");
                }
                else
                {
                    lblStatus.Text = "There was a problem with your order.  Please try again later.";
                }
            }
            else
            {
                lblStatus.Text = "Please add items to your shopping cart before checking out.";
            }
        }
        else
        {
            lblStatus.Text = "Please add items to your shopping cart before checking out.";
        }
    }
Exemplo n.º 2
0
    //This method fires when the 'Add to Cart' button is clicked
    protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        string itemID  = ((HiddenField)(FormView1.FindControl("HiddenField1"))).Value;
        string items   = ((Label)FormView1.FindControl("itemLabel")).Text;
        int    qty     = 1;
        var    rdbList = FormView1.FindControl("RadioButtonList1") as RadioButtonList;

        price = Convert.ToDecimal(rdbList.SelectedItem.Text);


//decimal price = decimal.Parse(((RadioButtonList)FormView1.FindControl("RadioButtonList1")).Text);

        //decimal price = RadioButtonList1.SelectedValue;

        //if the cart doesn't exist, create it.  Otherwise, retrieve it from the session and add the product to it.
        if (Session["ShoppingCart"] == null)
        {
            Shopping_Cart c = new Shopping_Cart();
            c.AddProduct(itemID, items, price, qty);
            Session["ShoppingCart"] = c;
        }
        else
        {
            Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];
            c.AddProduct(itemID, items, price, qty);
            Session["ShoppingCart"] = c;
        }


        Response.Redirect("OrderSummary.aspx");
    }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Shopping_Cart shopping_Cart = db.Shopping_Cart.Find(id);

            db.Shopping_Cart.Remove(shopping_Cart);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
    //When the gridview has been bound to the data, calculate the order total and display in the Gridview footer
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];

        //Only do the calculation if the Gridview has something in it
        if (GridView1.Rows.Count > 0)
        {
            Label lblTotal = (Label)GridView1.FooterRow.FindControl("lblTotal");
            lblTotal.Text = c.GetTotal().ToString();
        }
    }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "id_shoppingcart,id_cliente,date,estado,metodo_pag,monto_total")] Shopping_Cart shopping_Cart)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shopping_Cart).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.id_cliente = new SelectList(db.Clientes, "id_cliente", "nombre_cliente", shopping_Cart.id_cliente);
     ViewBag.estado     = new SelectList(db.Estadoes, "id_estado", "descripcion", shopping_Cart.estado);
     ViewBag.metodo_pag = new SelectList(db.Metodo_Pago, "id_metodo_pago", "descripcion", shopping_Cart.metodo_pag);
     return(View(shopping_Cart));
 }
Exemplo n.º 6
0
    //Use the RowEditing event of the Gridview to update item quantities
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];

        string itemid = GridView1.Rows[e.NewEditIndex].Cells[0].Text;

        //string itemid = GridView1.SelectedRow.Cells[0].Text;
        int quantity = Convert.ToInt16(((TextBox)GridView1.Rows[e.NewEditIndex].FindControl("quantitytxt")).Text);

        c.UpdateQuantity(quantity, itemid);
        GridView1.EditIndex = -1;
        GridView1.DataBind();
    }
Exemplo n.º 7
0
    //Use the RowCommand event of the Gridview to handle removing items from the cart.  The CommandArgument property of the remove button supplies the product ID to remove
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Remove")
        {
            Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];
            c.RemoveProduct(e.CommandArgument.ToString());
            GridView1.DataBind();

            if (GridView1.Rows.Count == 0)
            {
                label1.Text = "Your shopping cart is empty";
            }
        }
    }
Exemplo n.º 8
0
        public ActionResult Remove(int id)
        {
            Shopping_Cart cart = (Shopping_Cart)Session["cart"];

            if (cart == null)
            {
                cart = new Shopping_Cart();
            }

            cart.RemoveItem(id);

            Session["cart"] = cart;
            return(Redirect(Request.UrlReferrer.ToString()));
        }
Exemplo n.º 9
0
        public ActionResult Update(int id, int amount)
        {
            Shopping_Cart cart = (Shopping_Cart)Session["cart"];

            if (cart == null)
            {
                cart = new Shopping_Cart();
            }

            cart.UpdateAmount(id, amount);

            Session["cart"] = cart;
            return(Redirect(Request.UrlReferrer.ToString()));
        }
Exemplo n.º 10
0
        // GET: Shopping_Cart/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Shopping_Cart shopping_Cart = db.Shopping_Cart.Find(id);

            if (shopping_Cart == null)
            {
                return(HttpNotFound());
            }
            return(View(shopping_Cart));
        }
Exemplo n.º 11
0
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //this variable ct is to count the number of selections in checkboxes
        //the ID of the selected items is combined to make the final ID for the Order placement
        //the DataBase is designed so as to facilitate this transaction
        //We know that itemID is integer type, if the final ID results in a number(more than 10 digits) beyond the range of int it will be a problem
        //So we make sure to consider only the first 9 selected items
        int    ct     = 0;
        string itemID = "";
        string items  = "";
        int    qty    = 1;

        if (e.CommandName == "order")
        {
            foreach (GridViewRow rw in GridView1.Rows)
            {
                if (((CheckBox)GridView1.Rows[rw.RowIndex].FindControl("checkbox1")).Checked)
                {
                    ct++;
                    if ((ct <= 9))
                    {
                        itemID = itemID + ((Label)(rw.FindControl("Label1"))).Text;
                        items  = items + "," + ((Label)(rw.FindControl("Label5"))).Text;
                        price  = price + Convert.ToDecimal(((Label)rw.FindControl("Label2")).Text);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (Session["ShoppingCart"] == null)
            {
                Shopping_Cart c = new Shopping_Cart();
                c.AddProduct(itemID, items, price, qty);
                Session["ShoppingCart"] = c;
            }
            else
            {
                Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];
                c.AddProduct(itemID, items, price, qty);
                Session["ShoppingCart"] = c;
            }


            Response.Redirect("OrderSummary.aspx");
        }
    }
Exemplo n.º 12
0
        public ActionResult UserCart(int?num, int?id)
        {
            //確認登入狀態
            if (Session["m_id"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                var userr = int.Parse(Session["m_id"].ToString());
                using (conn)
                {
                    //將該筆商品 加入購物車
                    if (num != null)
                    {
                        string sql  = "SELECT *FROM dbo.Shopping_Cart WHERE dbo.Shopping_Cart.m_id =@mid  AND dbo.Shopping_Cart.pd_id =@pdid";
                        var    Cart = conn.QuerySingleOrDefault(sql, new { mid = userr, pdid = id });


                        //已經有產品了 更新數量
                        if (Cart != null)
                        {
                            num += Cart.cart_quantity;
                            string sqlUpdata = "Update dbo.Shopping_Cart SET cart_quantity=@Num WHERE dbo.Shopping_Cart.m_id=" + userr +
                                               "AND dbo.Shopping_Cart.pd_id=" + Cart.pd_id;
                            conn.Execute(sqlUpdata, new { Num = num });
                        }
                        //沒有就新增進去
                        else
                        {
                            Shopping_Cart sc = new Shopping_Cart();
                            sc.m_id          = userr;
                            sc.pd_id         = id;
                            sc.cart_quantity = num;
                            db.Shopping_Cart.Add(sc);
                            db.SaveChanges();
                        }
                    }
                }

                //加入購物車後 返回商品頁面
                string temp   = Session["Nowitem"].ToString();
                int    tempid = Convert.ToInt32(Session["nowproduct"].ToString());

                return(RedirectToAction(Session["Nowitem"].ToString(), new { id = tempid }));
            }
        }
Exemplo n.º 13
0
        // GET: Shopping_Cart/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Shopping_Cart shopping_Cart = db.Shopping_Cart.Find(id);

            if (shopping_Cart == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_cliente = new SelectList(db.Clientes, "id_cliente", "nombre_cliente", shopping_Cart.id_cliente);
            ViewBag.estado     = new SelectList(db.Estadoes, "id_estado", "descripcion", shopping_Cart.estado);
            ViewBag.metodo_pag = new SelectList(db.Metodo_Pago, "id_metodo_pago", "descripcion", shopping_Cart.metodo_pag);
            return(View(shopping_Cart));
        }
Exemplo n.º 14
0
        public void ShoppingCartRepositoryTests_Delete()
        {
            ShoppingCartRepository repository = new ShoppingCartRepository();
            var model = new Shopping_Cart()
            {
                Shopping_Cart_ID = 3
            };

            repository.Delete(3);
            var result = repository.GetAll();
            var test   = result.Where(x => x.Shopping_Cart_ID == 3);

            foreach (var item in test)
            {
                Assert.IsTrue(item.Shopping_Cart_ID == 3);
            }
        }
Exemplo n.º 15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check whether the shopping cart is empty.  If not, display its contents in a Gridview
        if (Session["ShoppingCart"] == null)
        {
            label1.Text = "Your shopping cart is empty";
        }
        else
        {
            Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];
            GridView1.DataSource = c.Products;

            if (!IsPostBack)
            {
                GridView1.DataBind();
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
//Here, we simply bind the list of products in the cart to the repeater control to generate the necessary form fields.
        //Then, reset the cart by setting the session variable to null.

        if (!IsPostBack)
        {
            if (Session["ShoppingCart"] != null)
            {
                Shopping_Cart c = (Shopping_Cart)Session["ShoppingCart"];

                rptItems.DataSource = c.Products;
                rptItems.DataBind();

                Session["ShoppingCart"] = null;
            }
        }
    }
        public bool CreateShoppingCart(string _account, int Product_ID, int Quantity, string Size, string Color)
        {
            //宣告 庫存,購物車,產品 的 Rpository
            StockRepository        sizeQuantityRepository = RepositoryContainer.GetInstance <StockRepository>();
            ShoppingCartRepository shoppingCart           = RepositoryContainer.GetInstance <ShoppingCartRepository>();
            ProductsRepository     products = RepositoryContainer.GetInstance <ProductsRepository>();

            //先取得那項產品庫存 放到 stock
            var stock = sizeQuantityRepository.GetByPK(Product_ID, Size, Color);

            //如果庫存量少與需求量 回傳 false
            if (stock.Quantity < Quantity)
            {
                return(false);
            }
            //取得 目前 Account 的 購物車
            var myCart = shoppingCart.GetByAccount(_account);
            //查看購物車是否有那項產品
            //如果有 把需要的數量 新增 進原有的購物車的裡面
            var items = myCart.FirstOrDefault(x => (x.Product_ID == Product_ID) && (x.size == Size) && (x.Color == Color));

            if (items != null)
            {
                //去更新購物車的那項產品
                shoppingCart.Update(items.Shopping_Cart_ID, items.Quantity + Quantity);
            }
            else
            {
                //如果購物車沒有那項產品就新增一項產品進到購物車
                var model = new Shopping_Cart()
                {
                    Account    = _account,
                    Product_ID = Product_ID,
                    size       = Size,
                    UnitPrice  = products.GetByProduct_ID(Product_ID).UnitPrice,
                    Quantity   = (short)Quantity,
                    Color      = Color,
                };
                shoppingCart.Create(model);
            }
            return(true);
        }
Exemplo n.º 18
0
        // GET: ShoppingCart
        public ActionResult Add(int id, string mau, int size, int amount)
        {
            Shopping_Cart cart = (Shopping_Cart)Session["cart"];

            if (cart == null)
            {
                cart = new Shopping_Cart();
            }

            ShopModel db = new ShopModel();
            Giay      g  = db.Giays.Find(id);

            if (g != null)
            {
                cart.InsertItem(g.Magiay, g.Tengiay, (double)g.Giaban, mau /*g.ChiTietMaus.Select(x => x.Mau.Tenmau).ToList()*/, size /*g.ChiTietSizes.Select(y => y.Size.Sosize).ToList()*/, amount);
            }

            Session["cart"] = cart;
            return(Redirect(Request.UrlReferrer.ToString()));
        }
Exemplo n.º 19
0
        public void ShoppingCartRepositoryTests_Create()
        {
            ShoppingCartRepository repository = new ShoppingCartRepository();
            var model = new Shopping_Cart()
            {
                Account    = "Bill",
                Product_ID = 1,
                Quantity   = 5,
                size       = "M"
            };

            repository.Create(model);
            var result = repository.GetAll();
            var test   = result.Where(x => x.Account == "Bill");

            foreach (var item in test)
            {
                Assert.IsTrue(item.Account == "Bill");
            }
        }
Exemplo n.º 20
0
        public void ShoppingCartRepositoryTests_Update()
        {
            ShoppingCartRepository repository = new ShoppingCartRepository();
            var model = new Shopping_Cart()
            {
                Shopping_Cart_ID = 3,
                Account          = "Bill",
                Product_ID       = 3,
                Quantity         = 3,
                UnitPrice        = 150,
                Discount         = 0,
                size             = "s"
            };

            repository.Update(3, 5);
            var result = repository.GetAll();
            var test   = result.Where(x => x.Quantity == 3);

            foreach (var item in test)
            {
                Assert.IsTrue(item.Quantity == 3);
            }
        }
Exemplo n.º 21
0
 partial void InsertShopping_Cart(Shopping_Cart instance);
Exemplo n.º 22
0
 partial void UpdateShopping_Cart(Shopping_Cart instance);
Exemplo n.º 23
0
 partial void DeleteShopping_Cart(Shopping_Cart instance);