示例#1
0
        public void Luudonhang(Donhangtongquan a, int maKH, Giohang giohang)
        {
            try
            {
                using (var db = new MainContext())
                {
                    var dhkh = new Domain.EfModels.DonHangKH();
                    dhkh.KhachHangId = maKH.ToString();

                    dhkh.Diachi       = a.address;
                    dhkh.Dienthoai    = a.phoneNumber;
                    dhkh.Ghichu       = a.Note;
                    dhkh.NgayDatMua   = DateTime.Now;
                    dhkh.TinhTrangDH  = 1;
                    dhkh.Tongtien     = giohang.TinhtongtienCart();
                    dhkh.PhiVanChuyen = 0;

                    dhkh = db.DonHangKHs.Add(dhkh);
                    db.SaveChanges();

                    Luuchitietdonhang(giohang, db, dhkh.Id);
                }
            }
            catch (Exception e) { }
        }
示例#2
0
        public RedirectToRouteResult ThemVaoGio(int iMaSP, string iSize)
        {
            if (Session["giohang"] == null)
            {
                Session["giohang"] = new List <Giohang>();
            }
            List <Giohang> giohang = Session["giohang"] as List <Giohang>;

            string size = "M";

            if (giohang.FirstOrDefault(m => m.iMaSP == iMaSP) == null)
            {
                SanPham sp      = db.SanPhams.FirstOrDefault(n => n.MaSP == iMaSP);
                Giohang newItem = new Giohang()
                {
                    iMaSP       = iMaSP,
                    iTenSP      = sp.TenSP,
                    iSL         = 1,
                    iAnhSP      = sp.AnhSP,
                    iGiaHienTai = (float)sp.GiaHienTai,
                    iSize       = size,
                };
                giohang.Add(newItem);
            }
            else
            {
                Giohang giohang1 = giohang.FirstOrDefault(m => m.iMaSP == iMaSP);
                giohang1.iSL++;
            }
            Session["tongtien"] = TongTien();
            return(RedirectToAction("Index", "Giohang", new { id = iMaSP, iSize = size }));
        }
示例#3
0
        //thêm giỏ hàng
        public ActionResult ThemGiohang(int ma_sp, string url)
        {
            sanpham sp = db.sanphams.SingleOrDefault(n => n.sanpham_id == ma_sp);

            if (sp == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //khởi tạo giỏ hàng &lấy ra session giohang
            List <Giohang> listGiohang = LayGiohang();
            //kiểm tra sách đã tồn tại trong session[Giohang] hay chưa?
            Giohang gh_sp = listGiohang.Find(n => n.sanpham_id == ma_sp);

            if (gh_sp == null)
            {
                gh_sp = new Giohang(ma_sp);
                //add sản phẩm mới vào list
                listGiohang.Add(gh_sp);
                return(Redirect(url));
            }
            else
            {
                gh_sp.soluong_sp++;
                return(Redirect(url));
            }
        }
示例#4
0
        //cập nhật giỏ hàng
        public ActionResult CapnhatGiohang(int ma_sp, FormCollection f)
        {
            //kiểm tra mã sản phẩm
            sanpham sp = db.sanphams.SingleOrDefault(n => n.sanpham_id == ma_sp);

            if (sp == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //lấy giỏ hàng từ session
            List <Giohang> listGiohang = LayGiohang();
            //kiểm tra sản phẩm có tồn tại  trong session
            Giohang gh_sp = listGiohang.SingleOrDefault(n => n.sanpham_id == ma_sp);

            //nếu tồn tại cho sửa
            if (gh_sp != null)
            {
                gh_sp.soluong_sp = int.Parse(f["txtSoluong"].ToString());
                //phut 14
            }

            //kh gửi biến model ,chỉ gọi về nỏ nên kh trả về view
            //lấy giá trị từ giỏ hàng
            return(RedirectToAction("Giohang"));
        }
示例#5
0
        //xóa giỏ hàng
        public ActionResult XoaGiohang(int ma_sp)
        {
            //kiểm tra mã sản phẩm
            sanpham sp = db.sanphams.SingleOrDefault(n => n.sanpham_id == ma_sp);

            //nếu ghép sai mã sản phẩm thì trả về trang lỗi
            if (sp == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //lấy giỏ hàng từ session
            List <Giohang> listGiohang = LayGiohang();
            //kiểm tra sản phẩm có tồn tại  trong session
            Giohang gh_sp = listGiohang.SingleOrDefault(n => n.sanpham_id == ma_sp);

            //nếu tồn tại cho sửa
            if (gh_sp != null)
            {
                listGiohang.RemoveAll(n => n.sanpham_id == ma_sp);
            }
            if (listGiohang.Count == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Giohang"));
        }
        public ActionResult MuaNgay(int id)
        {
            //Product product = db.Products.SingleOrDefault(n => n.Products_id == id);
            //if (product == null)
            //{
            //    Response.StatusCode = 404;
            //    return null;
            //}
            //Lấy ra session giỏ hàng
            List <Giohang> lstGioHang = LayGioHang();
            Giohang        gh         = lstGioHang.Find(n => n.iMaSP == id);

            if (gh == null)
            {
                gh = new Giohang();
                //gh.iMaSP = product.Products_id;
                Product prod = db.Products.SingleOrDefault(n => n.Products_id == id);
                gh.iMaSP    = prod.Products_id;
                gh.sHinhAnh = "img";
                gh.sTenSP   = prod.Name;
                Discount discount = db.Discounts.SingleOrDefault(n => n.Discount_id == prod.Discount_id);
                gh.dKhuyenMai = (Double)discount.value;
                gh.dDonGia    = Convert.ToDouble(prod.Gia);
                gh.iSoLuong++;
                lstGioHang.Add(gh);
                return(RedirectToAction("Index"));
            }
            else
            {
                gh.iSoLuong++;
                return(RedirectToAction("Index"));
            }
        }
        //Thêm giỏ hang
        public ActionResult ThemGioHang(int iMaSP, string strURL)
        {
            Product product = db.Products.SingleOrDefault(n => n.Products_id == iMaSP);

            if (product == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //Lấy ra session giỏ hàng
            List <Giohang> lstGioHang = LayGioHang();
            Giohang        gh         = lstGioHang.Find(n => n.iMaSP == iMaSP);

            if (gh == null)
            {
                //gh = new Giohang(iMaSP);
                gh = new Giohang();
                Product prod = db.Products.SingleOrDefault(n => n.Products_id == product.Products_id);
                gh.iMaSP    = prod.Products_id;
                gh.sHinhAnh = "img";
                gh.sTenSP   = prod.Name;
                Discount discount = db.Discounts.SingleOrDefault(n => n.Discount_id == product.Discount_id);
                gh.dKhuyenMai = (Double)discount.value;
                gh.dDonGia    = Convert.ToDouble(prod.Gia);
                gh.iSoLuong++;
                lstGioHang.Add(gh);
                return(Redirect(strURL));
            }
            else
            {
                gh.iSoLuong++;
                return(Redirect(strURL));
            }
        }
        public RedirectToRouteResult ThemVaoGio(string iMaSP)
        {
            if (Session["giohang"] == null)
            {
                Session["giohang"] = new List <Giohang>();
            }

            List <Giohang> giohang = Session["giohang"] as List <Giohang>;


            if (giohang.FirstOrDefault(m => m.iMaSP == iMaSP) == null)
            {
                SanPham sp = db.SanPham.FirstOrDefault(n => n.MaSP == iMaSP);

                Giohang newItem = new Giohang()
                {
                    iMaSP       = iMaSP,
                    iTenSP      = sp.TenSP,
                    iSL         = 1,
                    iAnhSP      = sp.AnhSP,
                    iGiaHienTai = (float)sp.GiaHienTai
                };
                ViewBag.TongTien = TongTien();
                giohang.Add(newItem);
            }
            else
            {
                Giohang giohang1 = giohang.FirstOrDefault(m => m.iMaSP == iMaSP);
                giohang1.iSL++;
            }
            return(RedirectToAction("Index", "Giohang", new { id = iMaSP }));
        }
示例#9
0
        public RedirectToRouteResult ThemVaoGio1(int iMaSP, string iSize)
        {
            if (Session["giohang"] == null)
            {
                Session["giohang"] = new List <Giohang>();
            }
            List <Giohang> giohang = Session["giohang"] as List <Giohang>;

            string size = "M";

            if (giohang.FirstOrDefault(m => m.iMaSP == iMaSP) == null)
            {
                SanPham sp      = db.SanPhams.FirstOrDefault(n => n.MaSP == iMaSP);
                Giohang newItem = new Giohang()
                {
                    iMaSP       = iMaSP,
                    iTenSP      = sp.TenSP,
                    iSL         = 1,
                    iAnhSP      = sp.AnhSP,
                    iGiaHienTai = (float)sp.GiaHienTai,
                    iSize       = size,
                };
                giohang.Add(newItem);
            }
            else
            {
                Giohang giohang1 = giohang.FirstOrDefault(m => m.iMaSP == iMaSP);
                giohang1.iSL++;
            }
            Session["tongtien"] = TongTien();
            DialogResult dlr = MessageBox.Show("Đã thêm sản phẩm vào giỏ hàng?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

            return(RedirectToAction("Details", "ClothesStore", new { id = iMaSP, iSize = size }));
        }
        public ActionResult Xoagiohangpartial(int isp)
        {
            List <Giohang> lstGiohang = laygiohang();
            Giohang        sanpham    = lstGiohang.SingleOrDefault(n => n.iMadt == isp); // kt sanpham co trong gio k?

            lstGiohang.RemoveAll(n => n.iMadt == isp);
            return(RedirectToAction("Index", "Home"));
        }
示例#11
0
        public ActionResult UpdateCart(int masp, FormCollection collection)
        {
            List <Giohang> lstGiohang = Laygiohang();
            Giohang        sampham    = lstGiohang.SingleOrDefault(f => f.iId == masp);

            if (sampham != null)
            {
                sampham.iSoluong = int.Parse(collection["quantity"].ToString());
            }
            return(RedirectToAction("Giohang"));
        }
示例#12
0
        public ActionResult CapnhatGiohang(int iMaDC, FormCollection f)
        {
            List <Giohang> lstGiohang = Laygiohang();
            Giohang        dungcu     = lstGiohang.SingleOrDefault(n => n.iMaDungCu == iMaDC);

            if (dungcu != null)
            {
                dungcu.iSoluong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("Giohang"));
        }
示例#13
0
        public RedirectToRouteResult XoaKhoiGio(int iMaSP)
        {
            List <Giohang> giohang = Session["giohang"] as List <Giohang>;
            Giohang        itemXoa = giohang.FirstOrDefault(m => m.iMaSP == iMaSP);

            if (itemXoa != null)
            {
                giohang.Remove(itemXoa);
            }
            return(RedirectToAction("Index"));
        }
示例#14
0
        public ActionResult CNGioHang(string MaSP, FormCollection collection)
        {
            List <Giohang> lgh = Laygiohang();
            Giohang        sp  = lgh.SingleOrDefault(n => n.MaSP == MaSP);

            if (sp != null)
            {
                sp.SoLuong = int.Parse(collection["txtSoluong"].ToString());
            }
            return(RedirectToAction("GioHang"));
        }
示例#15
0
        public ActionResult CapNhatGioHang(int gh_Masach, FormCollection f)
        {
            List <Giohang> lstGioHang = Laygiohang();
            Giohang        sanPham    = lstGioHang.SingleOrDefault(sp => sp.Gh_Masach == gh_Masach);

            if (sanPham != null)
            {
                sanPham.Gh_soLuong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("GioHang"));
        }
示例#16
0
        public ActionResult CapnhatGiohang(int iMaSP, FormCollection f)
        {
            List <Giohang> lstGiohang = Laygiohang();
            Giohang        sanpham    = lstGiohang.SingleOrDefault(n => n.iMasach == iMaSP);

            if (sanpham != null)
            {
                sanpham.iSoluong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("GioHang"));
        }
示例#17
0
        //Cập nhật giỏ hàng
        public ActionResult capnhatGH(int sMaSP, FormCollection f)
        {
            List <Giohang> lstGiohang = LayGioHang();

            Giohang sanpham = lstGiohang.SingleOrDefault(n => n.sMaSP == sMaSP);

            if (sanpham != null)
            {
                sanpham.sSoLuong = int.Parse(f["txtSoLuong"].ToString());
            }
            return(RedirectToAction("chitietGH"));
        }
        public ActionResult XoaGiohang(string iMaSp)
        {
            List <Giohang> lsGiohang = Laygiohang();
            Giohang        sanpham   = lsGiohang.SingleOrDefault(n => n.iMasanpham == iMaSp);

            if (sanpham != null)
            {
                lsGiohang.RemoveAll(n => n.iMasanpham == iMaSp);
                return(RedirectToAction("HienThiGioHang"));
            }
            return(RedirectToAction("HienThiGioHang"));
        }
示例#19
0
 public ActionResult Capnhatgiohang(int id, FormCollection f)
 {
     // lay hang tu session
     List<Giohang> listG = Laygiohang();
     // kiemtra sach dax co trong gio hang
     Giohang sp = listG.SingleOrDefault(n => n.idSp == id);
     // chi sua so luong khi no ton tai
     if (sp != null)
     {
         sp.soLuong = int.Parse(f["soluong"].ToString());
     }
     return RedirectToAction("Giohang");
 }
示例#20
0
        // Thêm giỏ hàng
        public ActionResult Themgiohang(int idProduct, int quantity)
        {
            List <Giohang> lstGiohang = Laygiohang();
            Giohang        sanpham    = lstGiohang.Find(n => n.iId == idProduct);

            if (sanpham == null)
            {
                sanpham          = new Giohang(idProduct);
                sanpham.iSoluong = quantity;
                lstGiohang.Add(sanpham);
            }
            return(RedirectToAction("Index", "Product"));
        }
        public ActionResult hienthiChiTiet(string ma)
        {
            List <ChiTietHD> cthd  = db.ChiTietHDs.Where(t => t.idHoaDon == ma).ToList();
            List <Giohang>   lstgh = new List <Giohang>();

            foreach (var item in cthd)
            {
                Giohang gh = new Giohang(item.idSanPham);
                lstgh.Add(gh);
            }
            ViewBag.Tongsoluong = TongSoLuong();
            ViewBag.Tongtien    = TongTien();
            return(View(lstgh));
        }
示例#22
0
        //cap nhat gio hang
        public ActionResult CapnhatGiohang(int iMaSP, FormCollection f)
        {
            //Lay gio hang session
            List <Giohang> lstGiohang = Laygiohang();
            //Kiểm tra game đã có trong session Giohang
            Giohang sanpham = lstGiohang.SingleOrDefault(n => n.iMaGame == iMaSP);

            //nếu tồn tại thì sửa số lượng
            if (sanpham != null)
            {
                sanpham.iSoluong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("GioHang"));
        }
示例#23
0
        public ActionResult CapnhatGiohang(int iMaSP, FormCollection f)
        {
            //lay gio hang tu session
            List <Giohang> lstGiohang = Laygiohang();
            //kiem tra giay da co trong sesssion[Giohang]
            Giohang sanpham = lstGiohang.SingleOrDefault(n => n.iMaSanPham == iMaSP);

            //neuton tai thi cho sua so luong
            if (sanpham != null)
            {
                sanpham.iSoLuong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("Giohang"));
        }
示例#24
0
        //Cap nha gio hang
        public ActionResult CapnhatGiohang(int iMaSP, FormCollection f)
        {
            //lay gio hang tu session
            List <Giohang> lstGiohang = Laygiohang();
            //kt sach da co rong sssion gio hang
            Giohang sanpham = lstGiohang.SingleOrDefault(n => n.iMasach == iMaSP);

            //neu ton tai sp
            if (sanpham != null)
            {
                sanpham.iSoluong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("Giohang"));
        }
示例#25
0
        //Cap nhat Giỏ hàng
        public ActionResult CapnhatGiohang(int iMaSP, FormCollection f)
        {
            //Lay gio hang tu Session
            List <Giohang> lstGiohang = Laygiohang();
            //Kiem tra sach da co trong Session["Giohang"]
            Giohang sanpham = lstGiohang.SingleOrDefault(n => n.idsp == iMaSP);

            //Neu ton tai thi cho sua Soluong
            if (sanpham != null)
            {
                sanpham.soluong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("Giohang"));
        }
示例#26
0
        //Cập nhật giỏ hàng
        public ActionResult CapnhatGiohang(int iMaSP, FormCollection f)
        {
            // Lấy giỏ hàng từ Session
            List <Giohang> lstGiohang = Laygiohang();
            // Kiểm tra sách đã có trong Session["Giohang"]
            Giohang sanpham = lstGiohang.SingleOrDefault(n => n.iMasach == iMaSP);

            // Nếu tồn tại thì cho sửa
            if (sanpham != null)
            {
                sanpham.iSoluong = int.Parse(f["txtSoluong"].ToString());
            }
            return(RedirectToAction("Giohang"));
        }
示例#27
0
 public ActionResult Xoagiohang(int id)
 {
     List<Giohang> listG = Laygiohang();
     Giohang sp = listG.SingleOrDefault(n => n.idSp == id);
     if (sp != null)
     {
         listG.RemoveAll(n => n.idSp == id);
         return RedirectToAction("Giohang");
     }
     if (listG.Count == 0)
     {
         return RedirectToAction("Index", "MyPham");
     }
     return RedirectToAction("Giohang");
 }
示例#28
0
        public ActionResult XoaGiohang(string iMasp)
        {
            List <Giohang> lstGiohang = Laygiohang();
            Giohang        sanpham    = lstGiohang.SingleOrDefault(n => n.chitiet.MaChiTiet == iMasp);

            if (sanpham != null)
            {
                lstGiohang.RemoveAll(n => n.chitiet.MaChiTiet == iMasp);
            }
            if (lstGiohang.Count == 0)
            {
                return(RedirectToAction("GioHang", "Giohang"));
            }
            return(RedirectToAction("GioHang"));
        }
示例#29
0
 private void Luuchitietdonhang(Giohang giohang, MainContext db, int maDH)
 {
     foreach (var temp in giohang.getGiohang())
     {
         var chiTiet = new ChiTietDonHang()
         {
             DonHangId = maDH,
             SanPhamId = temp.sanPham.Id,
             SoLuong   = temp.Soluong,
             ThanhTien = (decimal)temp.Thanhtien
         };
         db.ChiTietDonHangs.Add(chiTiet);
     }
     db.SaveChanges();
 }
示例#30
0
        public ActionResult XoaGiohang(int iMaSP)
        {
            List <Giohang> lstGiohang = Laygiohang();
            Giohang        sanpham    = lstGiohang.SingleOrDefault(n => n.iMasach == iMaSP);

            if (sanpham != null)
            {
                lstGiohang.RemoveAll(n => n.iMasach == iMaSP);
                return(RedirectToAction("GioHang"));
            }
            if (lstGiohang.Count == 0)
            {
                return(RedirectToAction("Index", "BookStore"));
            }
            return(RedirectToAction("GioHang"));
        }