예제 #1
0
        // GET: Books
        public ActionResult Index(string sortOrder, string titleSearch, string authorSearch, int?page)
        {
            // TODO: Keep title and author's name filter after applying a sort
            using (BookModel model = new BookModel())
            {
                ViewBag.ReadingOrderSortParam    = string.IsNullOrWhiteSpace(sortOrder) ? "readingOrderDesc" : "";
                ViewBag.TitleSortParam           = sortOrder == "titleAsc" ? "titleDesc" : "titleAsc";
                ViewBag.AuthorSortParam          = sortOrder == "authorAsc" ? "authorDesc" : "authorAsc";
                ViewBag.PublicationYearSortParam = sortOrder == "publicationYearAsc" ? "publicationYearDesc" : "publicationYearAsc";

                List <Book> booksList = Sort(sortOrder, model.GetList());
                booksList = FilterByTitleAndAuthor(booksList, titleSearch, authorSearch);

                return(View(booksList.ToPagedList(page ?? 1, ELEMENTS_PER_PAGE)));
            }
        }