예제 #1
0
        public IActionResult BookCatalogByGenre(int?genreId, string selectionType, int page = 1)
        {
            BookCatalogViewModel cvm = null;
            string uri = UriHelper.GetEncodedPathAndQuery(Request);

            switch (selectionType)
            {
            case "text":
                if (genreId != null || db.Genres.Find(genreId) != null)
                {
                    IEnumerable <Book> genreTextBooks = db.TextBooks
                                                        .AsEnumerable()
                                                        .Where(b => BooksFilteringHelper.GenresContains(b.Genres, genreId))
                                                        .OrderBy(b => b.BookName);
                    cvm = new BookCatalogViewModel
                    {
                        Title = "Все книги жанра \"" + db.Genres.Find(genreId).Name + "\"",
                        Books = genreTextBooks
                                .Skip((page - 1) * pageSize)
                                .Take(pageSize),
                        PageInfo = new PageInfo {
                            BaseUrl = PagingHelpers.RemovePageQuery(uri), PageNumber = page, PageSize = pageSize, TotalItems = genreTextBooks.Count()
                        }
                    };
                }
                else
                {
                    return(NotFound());
                }

                return(View("~/Views/Catalog/TextBookCatalog.cshtml", cvm));

            case "audio":
                if (genreId != null || db.Genres.Find(genreId) != null)
                {
                    IEnumerable <Book> genreAudioBooks = db.AudioBooks
                                                         .AsEnumerable()
                                                         .Where(b => BooksFilteringHelper.GenresContains(b.Genres, "Книги о программировании"))
                                                         .OrderBy(b => b.BookName);
                    cvm = new BookCatalogViewModel
                    {
                        Title = "Все аудиокниги жанра \"" + db.Genres.Find(genreId).Name + "\"",
                        Books = genreAudioBooks
                                .Skip((page - 1) * pageSize)
                                .Take(pageSize),
                        PageInfo = new PageInfo {
                            BaseUrl = PagingHelpers.RemovePageQuery(uri), PageNumber = page, PageSize = pageSize, TotalItems = genreAudioBooks.Count()
                        }
                    };
                }
                else
                {
                    return(NotFound());
                }

                return(View("~/Views/Catalog/AudioBookCatalog.cshtml", cvm));
            }

            return(NotFound());
        }
예제 #2
0
        public IActionResult MainCatalogByGenre(int?genreId)
        {
            if (genreId == null || db.Genres.Find(genreId) == null)
            {
                return(NotFound());
            }

            MainCatalogViewModel cvm = new MainCatalogViewModel
            {
                SelectedGenre = db.Genres.Find(genreId),
                Genres        = db.Genres.OrderBy(g => g.Name),
                TextBooks     = db.TextBooks
                                .AsEnumerable()
                                .Where(b => BooksFilteringHelper.GenresContains(b.Genres, genreId))
                                .OrderBy(b => b.BookName)
                                .Take(10),
                AudioBooks = db.AudioBooks
                             .AsEnumerable()
                             .Where(b => BooksFilteringHelper.GenresContains(b.Genres, genreId))
                             .OrderBy(b => b.BookName)
                             .Take(10)
            };

            return(View("~/Views/Catalog/MainCatalog.cshtml", cvm));
        }
예제 #3
0
        public IActionResult Index()
        {
            IEnumerable <TextBook>  textBooks  = db.TextBooks;
            IEnumerable <AudioBook> audioBooks = db.AudioBooks;

            IEnumerable <TextBook> newBooksList = textBooks
                                                  .Where(b => BooksFilteringHelper.BookIsNew(b, 30))
                                                  .Take(10)
                                                  .OrderBy(b => b.BookName);

            IEnumerable <TextBook> programmingBooksList = textBooks
                                                          .Where(b => BooksFilteringHelper.GenresContains(b.Genres, "Книги о программировании"))
                                                          .Take(10)
                                                          .OrderBy(b => b.BookName);

            IEnumerable <AudioBook> audioBooksList = audioBooks
                                                     .Take(10)
                                                     .OrderBy(b => b.BookName);

            IndexBookSet newBooksSet = new IndexBookSet
            {
                ActionLink = Url.Action("BookCatalogBySet", "Catalog", new { setName = "novelty", selectionType = "text" }),
                Info       = new List <string> {
                    "Мы добавляем лучшие новинки", "+100 книг каждый день. Модные авторы и эксклюзивные издательства"
                },
                TextBooks = newBooksList,
                Type      = "text"
            };

            IndexBookSet programmingBooksSet = new IndexBookSet
            {
                ActionLink = Url.Action("BookCatalogByGenre", "Catalog", new { genreId = db.Genres.FirstOrDefault(g => g.Name == "Книги о программировании").GenreId, selectionType = "text" }),
                Info       = new List <string> {
                    "Мы поможем вам развиваться", "Книги о программировании"
                },
                TextBooks = programmingBooksList,
                Type      = "text"
            };

            IndexBookSet audioBooksSet = new IndexBookSet
            {
                ActionLink = Url.Action("BookCatalog", "Catalog", new { selectionType = "audio" }),
                Info       = new List <string> {
                    "Неудобно читать - слушайте", "Более 1000 аудиокниг для взрослых и детей"
                },
                AudioBooks = audioBooksList,
                Type       = "audio"
            };

            IndexViewModel ivm = new IndexViewModel
            {
                Description = db.Descriptions.FirstOrDefault(d => d.TargetName == "LibNet Description"),
                BookSets    = new List <IndexBookSet> {
                    newBooksSet, programmingBooksSet, audioBooksSet
                },
                TextBooksCount  = textBooks.Count(),
                AudioBooksCount = audioBooks.Count()
            };

            return(View(ivm));
        }