Ejemplo n.º 1
0
        public ActionResult BookListFilter(Cart cart, MenuFilterViewModel model, int page = 1)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("BookList"));
            }
            IEnumerable <Book> books = repository.Books
                                       .Where(x => (string.IsNullOrEmpty(model.Genre) || x.Genre.GenreName.Equals(model.Genre)) &&
                                              x.Price >= model.MinPrice && x.Price <= model.MaxPrice);

            switch (model.SortItem)
            {
            case "Default":
            {
                books = books.OrderBy(x => x.BookId);
                break;
            }

            case "Name_ASC":
            {
                books = books.OrderBy(x => x.Name);
                break;
            }

            case "Name_DESC":
            {
                books = books.OrderByDescending(x => x.Name);
                break;
            }

            case "Price_ASC":
            {
                books = books.OrderBy(x => x.Price);
                break;
            }

            case "Price_DESC":
            {
                books = books.OrderByDescending(x => x.Price);
                break;
            }
            }
            ;

            BooksListViewModel bookList = new BooksListViewModel
            {
                Books = books,

                BooksInCart = cart.TotalCart.Select(x => x.Book.BookId),

                Pagination = new Pagination {
                    ItemsPerPage = 1
                }
            };

            return(View("BookList", bookList));
        }
Ejemplo n.º 2
0
        public PartialViewResult FilterMenu(MenuFilterViewModel model)
        {
            model.MinPrice = model.MinPrice == 0
                ? repository.Books.Min(x => (int?)x.Price) ?? 0
                : model.MinPrice;

            model.MaxPrice = model.MaxPrice == 0
                ? repository.Books.Max(x => (int?)x.Price) ?? 10_000
                : model.MaxPrice;

            return(PartialView(model));
        }