Exemplo n.º 1
0
 public ActionResult listproduct()
 {
     Session["count"] = 12; //kiểm soát số lượng hiển thị sản phẩm
     Session["temp"]  = 1;  //trạng thái phát hiện đang ở loại sp nào
     products         = db.get_product_discount().Where(s => s.LoaiSP == 1111 && s.Ishot == 1).Take(8).ToList();
     return(PartialView("_Viewproduct", products));
 }
Exemplo n.º 2
0
        // GET: Product
        public ActionResult Index(int?id)
        {
            Session["id"] = id;
            var spkm = db.SPkhuyenmais.Where(s => s.MaSP == id).FirstOrDefault();

            if (spkm != null)
            {
                var ttkm = db.Khuyenmais.Where(s => s.MaKM == spkm.MaSPKM).FirstOrDefault();
                if (ttkm != null)
                {
                    ViewBag.ttkm = ttkm;
                }
            }
            get_product_discount_Result data = new get_product_discount_Result();

            data = db.get_product_discount().Where(s => s.MaSP == id).FirstOrDefault();
            //kiểm tra hàng còn hay không
            var status = db.Sanphams.Where(s => s.MaSP == id).Select(s => s.SoLuong).FirstOrDefault();

            ViewBag.status = status;
            return(View(data));
        }
 public ActionResult Index(double?minprice, double?maxprice, int?loaisp, int?hangsx)
 {
     Session.Timeout = 1440;
     if (minprice != null && maxprice != null)
     {
         //nếu có (min,max) sẽ lọc ra danh sách sản phẩm để dùng bên /search/index
         products = db.get_product_discount().Where(s => s.Gia >= minprice && s.Gia <= maxprice).ToList();
         Session["filterresult"] = products; // lưu list vào session
     }
     else
     {
         Session["filterresult"] = null;   //nếu filter mà ko có (min,max)
     }
     return(RedirectToAction("index", "search", new { id = loaisp, mahang = hangsx, searchAdvanced = 1007 }));
 }
Exemplo n.º 4
0
        public ActionResult resultproduct(int?id, int?page, string btnsearch, int?mahang)
        {
            data.allsanphams = new List <Sanpham>();

            /*==============================Tìm kiếm theo từ khoá=======================================*/

            if (Session["btnsearch"] != null && Session["id"] == null)
            {
                if (Session["type"] != null && Session["type"].ToString() != "")
                {
                    /* tuỳ chọn tăng giảm sẽ dùng luôn session["sort"] trước đó đã được lưu */
                    /* sort chỉ hoạt động khi có giá trị của session["sort"] , mặc định sắp xếp theo giá*/
                    if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                    {
                        data.allsanphams = db.Sanphams.Where(s => s.TenSP.Contains(btnsearch)).ToList();
                        foreach (var item in data.allsanphams)
                        {
                            var x = db.get_product_discount().Where(s => s.MaSP == item.MaSP).FirstOrDefault();
                            listproducts.Add(x);
                        }
                        listproducts = listproducts.OrderByDescending(s => s.Gia).ToList();
                        if (Session["sort"] != null)
                        {
                            getgiambtnSearch(btnsearch);
                        }
                    }
                    else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                    {
                        data.allsanphams = db.Sanphams.Where(s => s.TenSP.Contains(btnsearch)).ToList();
                        foreach (var item in data.allsanphams)
                        {
                            var x = db.get_product_discount().Where(s => s.MaSP == item.MaSP).FirstOrDefault();
                            listproducts.Add(x);
                        }
                        listproducts = listproducts.OrderBy(s => s.Gia).ToList();
                        if (Session["sort"] != null)
                        {
                            gettangbtnSearch(btnsearch);
                        }
                    }
                }
                else
                {
                    data.allsanphams = db.Sanphams.Where(s => s.TenSP.Contains(btnsearch)).ToList();
                    foreach (var item in data.allsanphams)
                    {
                        var x = db.get_product_discount().Where(s => s.MaSP == item.MaSP).FirstOrDefault();
                        listproducts.Add(x);
                    }
                }
            }

            /*===========================================================================================*/

            /*===================================== Tìm kiếm theo Loại sản phẩm ============================*/
            if (Session["id"] != null && Session["mahang"] == null) //session["id"] là loại sản phẩm như đã nói.
            {
                //nếu có giá trị của type (tăng,giảm)
                if (Session["type"] != null && Session["type"].ToString() != "")
                {
                    /* tuỳ chọn tăng giảm sẽ dùng luôn session["sort"] trước đó đã được lưu */
                    /* sort chỉ hoạt động khi có giá trị của session["sort"] , mặc định sắp xếp theo giá*/
                    if (Session["searchAdvanced"] != null && Session["filterresult"] != null)       //đang sử dụng filter
                    {
                        listproducts = (List <get_product_discount_Result>)Session["filterresult"]; //Session["filterresult"] là danh sách đã được lọc theo (min,max) giá từ trước
                        listproducts = listproducts.Where(s => s.LoaiSP == id).ToList();
                        if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                        {
                            listproducts = listproducts.OrderByDescending(s => s.Gia).Where(s => s.LoaiSP == id).ToList();
                            if (Session["sort"] != null)
                            {
                                getgiamloai(id);
                            }
                        }
                        else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                        {
                            listproducts = listproducts.OrderBy(s => s.Gia).Where(s => s.LoaiSP == id).ToList();
                            if (Session["sort"] != null)
                            {
                                gettangloai(id);
                            }
                        }
                    }
                    else //dùng những tuỳ chọn search khác (ở navbar, ở header)
                    {
                        if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                        {
                            listproducts = db.get_product_discount().OrderByDescending(s => s.Gia).Where(s => s.LoaiSP == id).ToList();
                            if (Session["sort"] != null)
                            {
                                getgiamloai(id);
                            }
                        }
                        else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                        {
                            listproducts = db.get_product_discount().OrderBy(s => s.Gia).Where(s => s.LoaiSP == id).ToList();
                            if (Session["sort"] != null)
                            {
                                gettangloai(id);
                            }
                        }
                    }
                }
                else
                {                                                                             //show mặc định khi không chọn sắp xếp
                    //nếu sesion["sort"] != null thì ko có sự thay đổi, chỉ thay đổi khi chọn kiểu sắp xếp (tăng, giảm)
                    if (Session["searchAdvanced"] != null && Session["filterresult"] != null) //lấy sản phẩm từ bộ lọc filter
                    {
                        listproducts = (List <get_product_discount_Result>)Session["filterresult"];
                        listproducts = listproducts.Where(s => s.LoaiSP == id).ToList();
                    }
                    else
                    {
                        listproducts = db.get_product_discount().Where(s => s.LoaiSP == id).ToList();
                    }
                }
            }

            /*==========================================================================================*/

            /*===================================== Tìm kiếm theo Hãng sản phẩm ============================*/
            if (Session["mahang"] != null && Session["id"] == null)
            {
                //nếu có giá trị của type (tăng,giảm)
                if (Session["type"] != null && Session["type"].ToString() != "")
                {
                    /* tuỳ chọn tăng giảm sẽ dùng luôn session["sort"] trước đó đã được lưu */
                    /* sort chỉ hoạt động khi có giá trị của session["sort"] , mặc định sắp xếp theo giá*/
                    if (Session["searchAdvanced"] != null && Session["filterresult"] != null)
                    {
                        listproducts = (List <get_product_discount_Result>)Session["filterresult"];//Session["filterresult"] là danh sách đã được lọc theo (min,max) giá từ trước
                        listproducts = listproducts.Where(s => s.HangSX == mahang).ToList();
                        if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                        {
                            listproducts = listproducts.OrderByDescending(s => s.Gia).Where(s => s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                getgiamhang(mahang);
                            }
                        }
                        else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                        {
                            listproducts = listproducts.OrderBy(s => s.Gia).Where(s => s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                gettanghang(mahang);
                            }
                        }
                    }
                    else
                    {
                        if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                        {
                            listproducts = db.get_product_discount().OrderByDescending(s => s.Gia).Where(s => s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                getgiamhang(mahang);
                            }
                        }
                        else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                        {
                            listproducts = db.get_product_discount().OrderBy(s => s.Gia).Where(s => s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                gettanghang(mahang);
                            }
                        }
                    }
                }
                else
                {   //show mặc định khi không chọn sắp xếp
                    //nếu  sắp xếp != null thì ko có sự thay đổi, chỉ thay đổi khi chọn kiểu sắp xếp (tăng, giảm)
                    if (Session["searchAdvanced"] != null && Session["filterresult"] != null)
                    {
                        listproducts = (List <get_product_discount_Result>)Session["filterresult"];
                        listproducts = listproducts.Where(s => s.HangSX == mahang).ToList();
                    }
                    else
                    {
                        listproducts = db.get_product_discount().Where(s => s.HangSX == mahang).ToList();
                    }
                }
            }

            /*==========================================================================================*/


            /*==========================================================Tìm kiếm theo mã hãng và loại sản phẩm=========================================================================*/

            if (Session["mahang"] != null && Session["id"] != null) //session["id"] là loại sản phẩm như đã nói.
            {
                //nếu có giá trị của type (tăng,giảm)
                if (Session["type"] != null && Session["type"].ToString() != "")
                {
                    /* tuỳ chọn tăng giảm sẽ dùng luôn session["sort"] trước đó đã được lưu */
                    /* sort chỉ hoạt động khi có giá trị của session["sort"] , mặc định sắp xếp theo giá*/
                    if (Session["searchAdvanced"] != null && Session["filterresult"] != null)
                    {
                        listproducts = (List <get_product_discount_Result>)Session["filterresult"]; //Session["filterresult"] là danh sách đã được lọc theo (min,max) giá từ trước
                        listproducts = listproducts.Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                        if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                        {
                            listproducts = listproducts.OrderByDescending(s => s.Gia).Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                getgiamNavbar(mahang, id);
                            }
                        }
                        else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                        {
                            listproducts = listproducts.OrderBy(s => s.Gia).Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                gettangNavbar(mahang, id);
                            }
                        }
                    }
                    else
                    {
                        if (string.Compare(Session["type"].ToString(), "giam", true) == 0)
                        {
                            listproducts = db.get_product_discount().OrderByDescending(s => s.Gia).Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                getgiamNavbar(mahang, id);
                            }
                        }
                        else if (string.Compare(Session["type"].ToString(), "tang", true) == 0)
                        {
                            listproducts = db.get_product_discount().OrderBy(s => s.Gia).Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                            if (Session["sort"] != null)
                            {
                                gettangNavbar(mahang, id);
                            }
                        }
                    }
                }
                else
                {   //show mặc định khi không chọn sắp xếp
                    //nếu  sắp xếp != null thì ko có sự thay đổi, chỉ thay đổi khi chọn kiểu sắp xếp (tăng, giảm)
                    if (Session["searchAdvanced"] != null && Session["filterresult"] != null)
                    {
                        listproducts = (List <get_product_discount_Result>)Session["filterresult"];
                        listproducts = listproducts.Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                    }
                    else
                    {
                        listproducts = db.get_product_discount().Where(s => s.LoaiSP == id && s.HangSX == mahang).ToList();
                    }
                }
            }
            /*==============================================================================================================================================================================*/

            //đếm tống số sản phẩm tìm được
            ViewBag.countnumber = listproducts != null?listproducts.Count() : 0;

            return(PartialView("_Viewproductsearch", listproducts.ToPagedList(page ?? 1, 8)));
        }