Ejemplo n.º 1
0
        public ActionResult Product(int id)
        {
            FSanPham fSanPham = new FSanPham();

            ViewBag.SanPham = fSanPham.FindSanPham(id);
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Product(int masp, int soLuong)
        {
            FSanPham        fSanPham        = new FSanPham();
            FSanPhamGioHang fSanPhamGioHang = new FSanPhamGioHang();
            FGioHang        fGioHang        = new FGioHang();
            var             sp = fSanPham.FindSanPham(masp);

            if (sp.TenSP.Length > 40)
            {
                sp.TenSP = sp.TenSP.Substring(0, 35) + "...";
            }
            var            gioHang        = (GioHang)Session["GioHang"];
            SanPhamGioHang sanPhamGioHang = new SanPhamGioHang();

            if (Session["KhachHang"] != null)
            {
                KhachHang x = (KhachHang)Session["KhachHang"];
                if (gioHang == null)
                {
                    gioHang = fGioHang.NewGH(x);
                }
                gioHang            = fSanPhamGioHang.AddItem(masp, gioHang.ID, soLuong);
                Session["GioHang"] = gioHang;
                return(RedirectToAction("Shopcart"));
            }
            else
            {
                if (Request.Cookies["IDCart"] != null)
                {
                    string x          = Request.Cookies["IDCart"].Value;
                    var    giohangtam = fGioHang.GetGH_MaGH(Convert.ToInt32(x));
                    giohangtam         = fSanPhamGioHang.AddItem(masp, Convert.ToInt32(x), soLuong);
                    Session["GioHang"] = giohangtam;
                    return(RedirectToAction("Shopcart"));
                }
                else
                {
                    gioHang = fGioHang.NewGH();
                    Response.Cookies["IDCart"].Value   = gioHang.ID.ToString();
                    Response.Cookies["IDCart"].Expires = DateTime.Now.AddDays(1);
                    gioHang            = fSanPhamGioHang.AddItem(masp, gioHang.ID, soLuong);
                    Session["GioHang"] = gioHang;
                    return(RedirectToAction("Shopcart"));
                }
            }
        }