示例#1
0
        public async Task <IActionResult> ShowBooksByGenre(string genre, string searchExpr, int?page = 1)
        {
            IEnumerable <Book> books = new List <Book>();
            ShowBooksViewModel indexViewModel;

            if (string.IsNullOrEmpty(searchExpr))
            {
                books = await _booksRepository.GetBooksByGenre(genre);
            }
            else
            {
                books = await _booksRepository.GetBooksByFilter(searchExpr, genre);
            }

            indexViewModel = new ShowBooksViewModel
            {
                Books = _booksRepository.PartBooksForPage(books, page.Value, COUNT_ELEMS_ON_PAGE)
                        .Select(book => BookConverter.ConvertModelToViewModel(book)).ToList(),
                PageViewModel = new PageViewModel(books.Count(), page.Value, COUNT_ELEMS_ON_PAGE),
                Genre         = genre,
                SearchExpr    = String.IsNullOrEmpty(searchExpr) ? string.Empty : searchExpr,
                ActionName    = nameof(this.ShowBooksByGenre)
            };
            return(View(nameof(ShowBooks), indexViewModel));
        }
示例#2
0
        public ActionResult Edit(int id)
        {
            var book = BookConverter.ConvertModelToViewModel(_booksRepository.GetElem(id));

            return(View(new ActionBooksPagesViewModel
            {
                Book = book,
                Genres = new SelectList(_genresRepository.GetAllGenres(), nameof(Genre.Id), nameof(Genre.Title),
                                        _genresRepository.GetAllGenres().FirstOrDefault(g => g.Id == book.GenreId)),
                PrevPageUrl = HttpContext.Request.Headers["Referer"].ToString()
            }));
        }
示例#3
0
        public ActionResult Show(int id)
        {
            var book = BookConverter.ConvertModelToViewModel(_booksRepository.GetElem(id));

            return(View(book));
        }