Exemplo n.º 1
0
        public ActionResult ListSubCategories(int?page, int?itemsPerPage, string sortOrder, string currentFilter, string searchString)
        {
            if (!isAdmin())
            {
                return(RedirectToAction("LogIn", "Main"));
            }
            ViewBag.CurrentSort     = sortOrder;
            ViewBag.IdSortParm      = String.IsNullOrEmpty(sortOrder) ? "id_desc" : "";
            ViewBag.NameSortParm    = sortOrder == "Name" ? "name_desc" : "Name";
            ViewBag.CatNameSortParm = sortOrder == "CatName" ? "catname_desc" : "CatName";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            List <SubCategory> allSubCategories = _categoryBLL.getAllSub(null);

            switch (sortOrder)
            {
            case "id_desc":
                allSubCategories = allSubCategories.OrderByDescending(s => s.ID).ToList();
                break;

            case "name_desc":
                allSubCategories = allSubCategories.OrderByDescending(s => s.name).ToList();
                break;

            case "Name":
                allSubCategories = allSubCategories.OrderBy(s => s.name).ToList();
                break;

            case "catname_desc":
                allSubCategories = allSubCategories.OrderByDescending(s => s.catName).ToList();
                break;

            case "CatName":
                allSubCategories = allSubCategories.OrderBy(s => s.catName).ToList();
                break;

            default:
                allSubCategories = allSubCategories.OrderBy(s => s.ID).ToList();
                break;
            }

            ViewBag.CurrentItemsPerPage = itemsPerPage;

            List <SubCategoryInfo> list = new List <SubCategoryInfo>();

            foreach (var item in allSubCategories)
            {
                list.Add(
                    new SubCategoryInfo()
                {
                    ID             = item.ID,
                    name           = item.name,
                    categoriesName = item.catName
                });
            }

            return(View(list.ToPagedList(pageNumber: page ?? 1, pageSize: itemsPerPage ?? 15)));
        }