예제 #1
0
        public async Task <IActionResult> Category(int?categoryId, int?page, string searchString = "")
        {
            List <ServiceReference_Item.Item> lst_item = null;

            ViewBag.page       = page ?? 1;
            ViewBag.CategoryId = categoryId;
            int pageSize = 8;

            ViewData["CurrentFilter"] = searchString;
            ServiceReference_Category.Category catebyId;
            if (!String.IsNullOrEmpty(searchString))//nếu có nhập tìm kiếm thì đưa vào list tìm sp theo tên
            {
                lst_item         = (await itm.findItembyNameAsync(searchString)).ToList();
                ViewData["link"] = searchString;
            }
            else if (searchString == null && categoryId == null)
            {
                lst_item         = (await itm.getAllItemAsync()).ToList();
                ViewData["link"] = "All";
            }
            else
            {
                lst_item = (await itm.findItembyCategoryIdAsync((int)categoryId)).ToList();
                catebyId = await cs.findCategorybyIdAsync((int)categoryId);

                ViewData["link"] = catebyId.CategoryName;
            }

            var items = (from a in lst_item select a).AsQueryable();

            return(View(PaginatedList <ServiceReference_Item.Item> .CreateAsync(items, page ?? 1, pageSize)));
        }