コード例 #1
0
        public ActionResult TimSP(string key, string maloai, int?page)
        {
            SanPhamModel spm = new SanPhamModel();

            ViewBag.key    = key;
            ViewBag.maloai = maloai;
            return(PhanTrangSP(spm.AdvancedSearch(key, maloai, null, null, null), page, null));
        }
コード例 #2
0
        public ActionResult AdvancedSearchP(string term, string loai, string hangsx, string typeview, int?page, int?minprice, int?maxprice)
        {
            ViewBag.Name     = term;
            ViewBag.loai     = loai;
            ViewBag.hangsx   = hangsx;
            ViewBag.minprice = minprice;
            ViewBag.maxprice = maxprice;
            ViewBag.type     = typeview;
            var sp  = new SanPhamModel();
            var lst = sp.AdvancedSearch(term, loai, hangsx, minprice, maxprice);

            return(PhanTrangAdvanced(lst, page));
        }
コード例 #3
0
        //public ActionResult Sort(string jsonsort)
        //{
        //    dynamic item = JObject.Parse(jsonsort);
        //    var term = jsonsort.prop1;
        //    return AdvancedSearchP(null, null, null, null);
        //}
        public ActionResult AdvancedSearchP(string term, string loai, string hangsx, string typeview, int?page, int?minprice, int?maxprice, int?typepagelist, int?typesearch, int?typesort)
        {
            ViewBag.Name         = term;
            ViewBag.loai         = loai;
            ViewBag.hangsx       = hangsx;
            ViewBag.minprice     = minprice;
            ViewBag.maxprice     = maxprice;
            ViewBag.type         = typeview;
            ViewBag.typesearch   = typesearch;
            ViewBag.typesort     = typesort;
            ViewBag.page         = page;
            ViewBag.typepagelist = typepagelist;

            // Phân loại search và sort
            SanPhamModel         sp = new SanPhamModel();
            IQueryable <SanPham> lst;
            int loaisearch = (typesearch ?? 0);// kiểu search là null thì sẽ là 0

            if (loaisearch == 0)
            {
                lst = sp.AdvancedSearch(term, loai, hangsx, minprice, maxprice);
                if (typesort == 1)
                {
                    lst = lst.OrderBy(e => e.GiaTien);
                }
                else if (typesort == 2)
                {
                    lst = lst.OrderByDescending(e => e.GiaTien);
                }
                else
                {
                    lst = lst.OrderByDescending(m => m.MaSP);
                }
            }
            else if (loaisearch == 1)
            {
                lst = sp.SPKhuyenMai();
                if (typesort == 1)
                {
                    lst = lst.OrderBy(e => e.GiaTien);
                }
                else if (typesort == 2)
                {
                    lst = lst.OrderByDescending(e => e.GiaTien);
                }
                else
                {
                    lst = lst.OrderByDescending(m => m.MaSP);
                }
            }
            else if (loaisearch == 2)
            {
                lst = sp.SPBanChay(0);
                if (typesort == 1)
                {
                    lst = lst.OrderBy(e => e.GiaTien);
                }
                else if (typesort == 2)
                {
                    lst = lst.OrderByDescending(e => e.GiaTien);
                }
                else
                {
                    lst = lst.OrderByDescending(m => m.MaSP);
                }
            }
            else if (loaisearch == 3)
            {
                lst = sp.SPHot();
                if (typesort == 1)
                {
                    lst = lst.OrderBy(e => e.GiaTien);
                }
                else if (typesort == 2)
                {
                    lst = lst.OrderByDescending(e => e.GiaTien);
                }
                else
                {
                    lst = lst.OrderByDescending(m => m.MaSP);
                }
            }
            else if (loaisearch == 4)
            {
                lst = sp.SPMoiNhap();
                if (typesort == 1)
                {
                    lst = lst.OrderBy(e => e.GiaTien);
                }
                else if (typesort == 2)
                {
                    lst = lst.OrderByDescending(e => e.GiaTien);
                }
                else
                {
                    lst = lst.OrderByDescending(m => m.MaSP);
                }
            }
            else
            {
                lst = ManagerObiect.getIntance().Laydanhsachsanphammoixem().AsQueryable();
                if (typesort == 1)
                {
                    lst = lst.OrderBy(e => e.GiaTien);
                }
                else if (typesort == 2)
                {
                    lst = lst.OrderByDescending(e => e.GiaTien);
                }
                else
                {
                    lst = lst.OrderByDescending(m => m.MaSP);
                }
            }
            // xét phân trang
            int typePT = (typepagelist ?? 0);

            if (typePT == 1)
            {
                return(PhanTrangAdvanced2(lst, page));
            }
            else
            {
                return(PhanTrangAdvanced(lst, page));
            }
        }