Exemple #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)));
        }
        public async Task <IActionResult> CategoryEdit(int id)
        {
            ServiceReference_Category.Category e = await cs.findCategorybyIdAsync(id);

            ServiceReference_Category.Category[] lst_categories = await cs.getAllCategoryAsync();

            CategoryModel cm = new CategoryModel()
            {
                categories   = lst_categories,
                CategoryId   = e.CategoryId,
                CategoryName = e.CategoryName,
                ImageCate    = e.ImageCate,
                ParentId     = e.ParentId,
                StatusCate   = e.StatusCate
            };

            ViewBag.flag    = flag;
            ViewBag.message = message;
            flag            = "";
            message         = "";
            return(View(cm));
        }