Example #1
0
        //Thêm giỏ hàng
        public ActionResult ThemGioDatHang(string sMaPhong, string strURL)
        {
            PhongDTO phong = p.getPhongByID(sMaPhong);

            if (phong == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //Lấy ra session giỏ hàng
            List <GioDatHang> lstGioDatHang = LayGioDatHang();
            //Kiểm tra sách này đã tồn tại trong session[GioDatHang] chưa
            GioDatHang sanpham = lstGioDatHang.Find(n => n.sMaphong == sMaPhong);

            if (sanpham == null)
            {
                sanpham = new GioDatHang(sMaPhong);
                //Add sản phẩm mới thêm vào list
                lstGioDatHang.Add(sanpham);
                return(Redirect(strURL));
            }
            else
            {
                sanpham.iSonguoi++;
                return(Redirect(strURL));
            }
        }
Example #2
0
        //Xóa giỏ hàng
        public ActionResult XoaGioDatHang(string sMaP)
        {
            //Kiểm tra masp
            PhongDTO phong = p.getPhongByID(sMaP);

            if (phong == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //Lấy giỏ hàng ra từ session
            List <GioDatHang> lstGioDatHang = LayGioDatHang();
            GioDatHang        sanpham       = lstGioDatHang.SingleOrDefault(n => n.sMaphong == sMaP);

            //Nếu mà tồn tại thì chúng ta cho sửa số lượng
            if (sanpham != null)
            {
                lstGioDatHang.RemoveAll(n => n.sMaphong == sMaP);
                DateTime ngayd = DateTime.Parse(sanpham.dNgayden);
                DateTime ngayi = DateTime.Parse(sanpham.dNgaydi);
                var      query = (from dv in entity.ngaydatphongs
                                  where dv.ngayden == ngayd && dv.ngaydi == ngayi
                                  select dv);
                entity.ngaydatphongs.RemoveRange(query);
                entity.SaveChanges();
            }
            if (lstGioDatHang.Count == 0)
            {
                var query = (from dv in entity.ngaydatphongs
                             select dv);

                entity.ngaydatphongs.RemoveRange(query);
                entity.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("GioDatHang"));
        }