Example #1
0
        public static List<TradeDTO> GetAllTradeWithAccountID(string id)
        {
            List<TradeDTO> rs = new List<TradeDTO>();

            string query = "select * from db3c04c35a9c6b45918ba3a551005e16ee.trade where AccountID like '" +id+ "'";

            DataTable dt = DataProvider.ExecuteQuery(query);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TradeDTO trade = new TradeDTO((string)dt.Rows[i]["AccountID"], (string)dt.Rows[i]["ProductID"]);

                trade.Quantity = (int)dt.Rows[i]["Quantity"];
                trade.Validated = (string)dt.Rows[i]["Validated"];
                trade.Date = (string)dt.Rows[i]["Date"];

                rs.Add(trade);
            }

            return rs;
        }
Example #2
0
        public ActionResult GioHang()
        {
            //get cookie
            string id ="";
            if (Request.Cookies.AllKeys.Contains("userID"))
            {
                id = Request.Cookies["userID"].Value;

            }

            if(id == "")
            {
                return Redirect("../Account/DangNhap");
            }

            List<TradeDTO> cart = (List<TradeDTO> )Session["cart"];
            if (cart == null)
            {
                cart = new List<TradeDTO>();
                Session.Add("cart", cart);
            }

                //update cart
                //add product
            if (Request["productID"] != null)
            {
                TradeDTO trade = new TradeDTO(id, Request["productID"]);
                cart.Add(trade);

            }
            //change quantity
            if (Request["changeIndex"] != null)
            {
                int index = int.Parse(Request["changeIndex"]);
                int quantity = int.Parse(Request["quantity"]);

                cart[index].Quantity = quantity;
            }

            //delete
            if (Request["deleteIndex"] != null)
            {
                int index = int.Parse(Request["deleteIndex"]);

                cart.RemoveAt(index);
            }

            //send
            Session["cart"] = cart;
            ViewBag.cart = cart;

            return View();
        }