Example #1
0
        public List <GioHangModel> getGioHangByND(int idND)
        {
            var ddh = db.DonDatHangs.SingleOrDefault(x => x.MaNguoiDung == idND && x.MaTrangThai == 0);
            List <GioHangModel> listGH;

            if (ddh != null)
            {
                List <ChiTietDonDatHang> listCTDDH = db.ChiTietDonDatHangs.Where(x => x.MaDDH == ddh.MaDDH).ToList();
                listGH = new List <GioHangModel>();
                foreach (var a in listCTDDH)
                {
                    var gh = new GioHangModel();

                    gh.TenSP    = a.SanPham.TenSP;
                    gh.HinhAnh  = a.SanPham.HinhAnh;
                    gh.SoLuong  = a.SoLuong;
                    gh.DonGia   = a.DonGia;
                    gh.NgayDat  = db.DonDatHangs.SingleOrDefault(x => x.MaDDH == a.MaDDH).NgayDat;
                    gh.MaSP     = a.MaSP;
                    gh.MaCHTDDH = a.MaCTDDH;
                    gh.MaDDH    = a.MaDDH;

                    listGH.Add(gh);
                }
            }
            else
            {
                listGH = new List <GioHangModel>();
            }

            return(listGH);
        }
Example #2
0
        public ActionResult Them(int sanPhamID, int soLuong = 1)
        {
            UserKH khachhang = Session["NguoiDung"] as UserKH;

            if (khachhang != null)
            {
                // Tham chiếu đến giỏ hàng lưu trong Session
                var gioHang = Session["GioHang"] as GioHangModel;
                if (gioHang == null)
                {
                    gioHang            = new GioHangModel();
                    Session["GioHang"] = gioHang;
                }
                var sanPhamChonMua = db.Saches
                                     .SingleOrDefault(sp => sp.SachID == sanPhamID);
                var item = new GioHangItem(sanPhamChonMua, soLuong);
                gioHang.Add(item);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("DangNhap", "KhachHangUser"));
            }
        }
Example #3
0
        public ActionResult Index()
        {
            var session = (DoAn.Common.Session.UserLogin)Session[DoAn.Common.Constants.USER_SESSION];
            var list    = new List <GioHangModel>();

            if (session != null)
            {
                var cart = new CartDao().GetProductsByIdUser(session.UserId);
                foreach (var item in cart)
                {
                    var cartitem = new GioHangModel();

                    var product     = new ProductDao().viewDetail(item.MaSanPham);
                    var categorydao = new CategoryDao();
                    if (categorydao.getSPChinh(product.Id) == 1)
                    {
                        cartitem.MaSanPham  = item.MaSanPham;
                        cartitem.Id         = item.Id;
                        cartitem.TenSanPham = product.TenSanPham;
                        cartitem.Anh        = product.Anh;
                        cartitem.SoLuong    = item.SoLuong;
                        cartitem.SanPhamThu = item.SanPhamThu;
                        cartitem.GiaBan     = new CartDao().Tien1LyTraSua(session.UserId, product.Id, item.SanPhamThu);
                        cartitem.ThanhTien  = cartitem.GiaBan * cartitem.SoLuong;
                        cartitem.MoTa       = new CartDao().getMoTa(product.Id, session.UserId, item.SanPhamThu);
                        list.Add(cartitem);
                    }
                }
                return(View(list));
            }
            else
            {
                return(View("/SanPham/Index"));
            }
        }
Example #4
0
        public ActionResult ChinhSua(GioHangModel model)
        {
            GioHangDAO ghDAO = new GioHangDAO();

            ghDAO.updateGH(model.MaCHTDDH, model.SoLuong);

            return(RedirectToAction("Index"));
        }
        public ActionResult ThemVaoGioHang(int idSP, int soLuong)
        {
            //Lấy sản phẩm
            string       linkAPI = $"product/productdetail?id={idSP}";
            ProductModel product = ProductDAO.ProductDetail(baseAddress, linkAPI);

            //nếu đã có giỏ hàng
            if (Session["Cart"] != null)
            {
                //Lấy ra giỏ hàng
                List <GioHangModel> cart = (List <GioHangModel>)Session["Cart"];
                if (cart.Exists(x => x.SanPham.id == idSP)) //Nếu tìm thấy sản phẩm trong giỏ thì tăng số lượng sản phẩm thêm 1
                {
                    foreach (var item in cart)
                    {
                        if (item.SanPham.id == idSP)
                        {
                            item.SoLuong += soLuong;
                            item.TongTien = item.SanPham.Price * item.SoLuong;
                        }
                    }
                }
                else //Nếu chưa có sản phẩm trong giỏ thì thêm sản phẩm vào giỏ
                {
                    var item = new GioHangModel();
                    item.SanPham  = product;
                    item.SoLuong  = soLuong;
                    item.TongTien = item.SanPham.Price * item.SoLuong;
                    cart.Add(item);
                }
                Session["Cart"] = cart;
            }
            else
            {
                var item = new GioHangModel();
                item.SanPham  = product;
                item.SoLuong  = soLuong;
                item.TongTien = item.SanPham.Price * item.SoLuong;
                var list = new List <GioHangModel>();
                list.Add(item);
                Session["Cart"] = list;
            }


            List <GioHangModel> cart1 = (List <GioHangModel>)Session["Cart"];

            @ViewBag.CartCount = cart1.Count;
            return(Json(cart1.Count()));
        }
Example #6
0
        public ActionResult AddToCart(int HangHoaID, int SoLuong = 1)
        {
            var gioHang = Session["GioHang"] as GioHangModel;

            if (gioHang == null)
            {
                gioHang            = new GioHangModel();
                Session["GioHang"] = gioHang;
            }
            HangHoa hangHoa = db.HangHoas.Find(HangHoaID);
            var     item    = new GioHangItem(hangHoa, SoLuong);

            gioHang.Them(item);
            return(RedirectToAction("Index"));
        }
        public ActionResult AddToCart(int HangHoaID, int SoLuong = 1)
        {
            string url     = $"hang-hoa/doc-theo-id?id={HangHoaID}";
            var    gioHang = Session["GioHang"] as GioHangModel;

            if (gioHang == null)
            {
                gioHang            = new GioHangModel();
                Session["GioHang"] = gioHang;
            }
            HangHoaInput hangHoa = ApiHelper <HangHoaInput> .RunPost(url);

            var item = new GioHangItem(hangHoa, SoLuong);

            gioHang.Them(item);
            return(RedirectToAction("Index"));
        }
Example #8
0
        public GioHangModel getItemGH(int idCTDDH, int idDDh)
        {
            var ct   = db.ChiTietDonDatHangs.Find(idCTDDH);
            var ddh  = db.DonDatHangs.Find(idDDh);
            var item = new GioHangModel();

            item.DonGia   = ct.DonGia;
            item.HinhAnh  = ct.SanPham.HinhAnh;
            item.MaCHTDDH = ct.MaCTDDH;
            item.MaDDH    = ct.MaDDH;
            item.MaSP     = ct.MaSP;
            item.NgayDat  = ddh.NgayDat;
            item.SoLuong  = ct.SoLuong;
            item.TenSP    = ct.SanPham.TenSP;

            return(item);
        }
Example #9
0
        public ActionResult Them(int sanPhamID, int soLuong = 1)
        {
            // Tham chiếu đến giỏ hàng lưu trong Session
            var gioHang = Session["GioHang"] as GioHangModel;

            if (gioHang == null)
            {
                gioHang            = new GioHangModel();
                Session["GioHang"] = gioHang;
            }
            var sanPhamChonMua = db.SanPhams.Find(sanPhamID);
            var item           = new GioHangItem(sanPhamChonMua, soLuong);

            gioHang.Add(item);

            //return RedirectToAction("Index");
            string returnUrl = Request.UrlReferrer.AbsoluteUri;

            return(Redirect(returnUrl));
        }
Example #10
0
 public GioHangController()
 {
     GioHang = new GioHangModel();
 }