Ejemplo n.º 1
0
        public IActionResult Index(string searchString, string sortOrder, string currentFilter, int?page)
        {
            ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["CurrentSort"]  = sortOrder;

            //var cosmetics = await _cosmeticsRepository.GetAllCosmeticsNameId(searchString, sortOrder);
            //return View(cosmetics);
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewData["CurrentFilter"] = searchString;
            //Database model = new Database()
            //{
            //    // Cheeses = CheeseData.GetAll()
            //    Cheeses = _database.Cheeses
            //};
            List <Cosmetics> ListSearchProduct = new List <Cosmetics>();

            ListSearchProduct = _cosmeticsRepository.GetAllWithType().ToList();
            if (!String.IsNullOrEmpty(searchString))
            {
                ListSearchProduct = ListSearchProduct.Where(s => s.Name.ToLower().Contains(searchString.ToLower())).ToList();
            }
            switch (sortOrder)
            {
            case "name_desc":
                ListSearchProduct = ListSearchProduct.OrderByDescending(s => s.Name).ToList();
                break;

            case "price_desc":
                ListSearchProduct.OrderByDescending(s => s.Price).ToList();
                break;
                //case "year_desc":
                //    model.Cheeses.OrderByDescending(s => s.Name);
                //    break;
            }
            int pageSize = 5;

            return(View(PaginatedListProduct <Cosmetics> .Create(ListSearchProduct.AsQueryable(), page ?? 1, pageSize)));
        }
Ejemplo n.º 2
0
        public IActionResult Index(string sortOrder, string searchString, string currentFilter, int?page)
        {
            ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["PriceSort"]    = String.IsNullOrEmpty(sortOrder) ? "price_desc" : "";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewData["CurrentFilter"] = searchString;
            List <Product> ListSearchProduct = new List <Product>();

            ListSearchProduct = _productRepository.GetAllWithType().ToList();
            if (!String.IsNullOrEmpty(searchString))
            {
                ListSearchProduct = ListSearchProduct.Where(s => s.ProductName.ToLower().Contains(searchString.ToLower())).ToList();
            }
            switch (sortOrder)
            {
            case "name_desc":
                ListSearchProduct = ListSearchProduct.OrderByDescending(s => s.ProductName).ToList();
                break;

            case "price_desc":
                ListSearchProduct.OrderByDescending(s => s.Price).ToList();
                break;
                //case "year_desc":
                //    model.Cheeses.OrderByDescending(s => s.Name);
                //    break;
            }
            int pageSize = 3;

            return(View(PaginatedListProduct <Product> .Create(ListSearchProduct.AsQueryable(), page ?? 1, pageSize)));
        }