コード例 #1
0
        // GET: DetailProduct
        public ActionResult DetailProduct(int product_id)
        {
            try
            {
                TblSanPhamDao _sanPhamDao = new TblSanPhamDao();
                Tbl_imageDao  _imageDao   = new Tbl_imageDao();

                List <Tbl_image> _listImageProduct = new List <Tbl_image>();
                Tbl_sanpham      _product          = new Tbl_sanpham();

                if (product_id != 0)
                {
                    _product          = _sanPhamDao.GetProductWithID(product_id);
                    _listImageProduct = _imageDao.GetListImage(product_id);

                    string   _size       = _product._size;
                    string[] _listSize   = _size.Split('-');
                    int      _first_size = Int32.Parse(_listSize.First());
                    int      _last_size  = Int32.Parse(_listSize.Last());
                    // đẩy dữ liệu sang FE

                    ViewBag._product          = _product;
                    ViewBag._listImageProduct = _listImageProduct;
                    ViewBag._first_size       = _first_size;
                    ViewBag._last_size        = _last_size;
                }
                return(View());
            }
            catch
            {
                // chuyển sang màn hình thông báo lỗi hệ thống
                return(RedirectToAction("Error", "ErrorProduct"));
            }
        }
コード例 #2
0
        // GET: Shop
        public ActionResult Shop(ShopInfo shopInfo)
        {
            TblSanPhamDao      _sanPhamDao  = new TblSanPhamDao();
            List <Tbl_sanpham> _listProduct = new List <Tbl_sanpham>();
            List <int>         listPaging   = new List <int>();


            // chỉ số trang hiện tại
            int currentPage = 1;

            if (shopInfo._currentPage != null)
            {
                currentPage = shopInfo._currentPage.Value;
            }
            int totalPage = 0;

            // số bản ghi tối đa trên 1 page
            int limit = 6;

            int limitPage = 3;

            string _product = "";

            _product = shopInfo._product;

            string _tensanpham = "";

            if (shopInfo._tensanpham != null || !"".Equals(shopInfo._tensanpham))
            {
                _tensanpham = shopInfo._tensanpham;
            }

            int _gia_min = -1;
            int _gia_max = 0;

            if (shopInfo._gia != null)
            {
                int price_range = int.Parse(shopInfo._gia);
                if (price_range == 500000)
                {
                    _gia_min = 0;
                    _gia_max = 500000;
                }
                else if (price_range == 700000)
                {
                    _gia_min = 500000;
                    _gia_max = 700000;
                }
                else if (price_range == 900000)
                {
                    _gia_min = 700000;
                    _gia_max = 900000;
                }
                else if (price_range == 1000000)
                {
                    _gia_min = 900000;
                    _gia_max = 99999999;
                }
            }

            int discount_price = 0;

            if (shopInfo._discount != null)
            {
                discount_price = int.Parse(shopInfo._discount);
            }

            int _type_product;

            if (Session["_product"] == null)
            {
                Session["_product"] = "";
            }
            if ("nike".Equals(shopInfo._product))
            {
                _type_product = Constants.NIKE;

                Action(ref shopInfo);

                // lấy tổng số user tìm được
                int totalProduct = _sanPhamDao.GetTotalproduct(_type_product, _tensanpham, _gia_min, _gia_max, discount_price);

                // lấy tổng số page
                totalPage = Common.GetTotalPage(totalProduct, limit);

                // lấy vị trí data cần lấy

                int offset = Common.GetOffset(currentPage, limit);


                // lấy danh sách trang hiện tại
                listPaging = Common.GetListPaging(totalProduct, limit, currentPage);

                _listProduct = _sanPhamDao.GetAllProductWithTyle(_type_product, offset, limit, _tensanpham, _gia_min, _gia_max, discount_price);
            }
            else if ("adidas".Equals(shopInfo._product))
            {
                _type_product = Constants.ADIDAS;
                // lấy tổng số user tìm được
                int totalProduct = _sanPhamDao.GetTotalproduct(_type_product, _tensanpham, _gia_min, _gia_max, discount_price);

                // lấy tổng số page
                totalPage = Common.GetTotalPage(totalProduct, limit);

                // lấy vị trí data cần lấy
                int offset = Common.GetOffset(currentPage, limit);

                // lấy danh sách trang hiện tại
                listPaging = Common.GetListPaging(totalProduct, limit, currentPage);

                _listProduct = _sanPhamDao.GetAllProductWithTyle(_type_product, offset, limit, _tensanpham, _gia_min, _gia_max, discount_price);
            }
            else if ("sneakers".Equals(shopInfo._product))
            {
                _type_product = Constants.SNEAKERS;
                // lấy tổng số user tìm được
                int totalProduct = _sanPhamDao.GetTotalproduct(_type_product, _tensanpham, _gia_min, _gia_max, discount_price);

                // lấy tổng số page
                totalPage = Common.GetTotalPage(totalProduct, limit);

                // lấy vị trí data cần lấy
                int offset = Common.GetOffset(currentPage, limit);

                // lấy danh sách trang hiện tại
                listPaging = Common.GetListPaging(totalProduct, limit, currentPage);

                _listProduct = _sanPhamDao.GetAllProductWithTyle(_type_product, offset, limit, _tensanpham, _gia_min, _gia_max, discount_price);
            }
            ViewBag._listProduct = _listProduct;
            ViewBag.listPaging   = listPaging;
            ViewBag.totalPage    = totalPage;
            ViewBag._currentPage = currentPage;
            ViewBag.limitPage    = limitPage;
            ViewBag.indexPage    = currentPage;
            ViewBag.product      = shopInfo._product;
            ViewBag._gia         = shopInfo._gia;
            ViewBag._discount    = shopInfo._discount;
            ViewBag._tensanpham  = shopInfo._tensanpham;

            return(View());
        }