Ejemplo n.º 1
0
        public ActionResult Random()
        {
            try
            {
                int userID = (int)Profile["ID"];
                int booksCount = manager.bookService.GetAllBooksCount();
                List<BookModel> books = new List<BookModel>();
                var book =
                    manager.bookService.OrderTake(ServiceOrderType.Likes, RandomInit.GetRandom().Next(booksCount), 1)
                        .FirstOrDefault();

                return View("Details", Book.GetBookPageModel(book.ID, userID));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return View("Error");
            }
        }
Ejemplo n.º 2
0
        public static BookIndexPageModel GetBookIndexPageModel()
        {
            BookIndexPageModel result = new BookIndexPageModel();
            var random             = RandomInit.GetRandom();
            int booksCount         = manager.bookService.GetAllBooksCount();
            List <BookModel> books = new List <BookModel>();

            for (int i = 0; i < 4; i++)
            {
                books.Add(
                    manager.bookService.OrderTake(ServiceOrderType.Likes, random.Next(booksCount), 1)
                    .FirstOrDefault()
                    .ToBookModel());
            }
            List <AuthorShortModel> authors = new List <AuthorShortModel>();
            int authorsCount = manager.authorService.GetAuthorsCount();

            for (int i = 0; i < 4; i++)
            {
                authors.Add(
                    manager.authorService.OrderTake(random.Next(authorsCount), 1).FirstOrDefault().ToAuthorShortModel());
            }
            List <GenreFirstModel> genres = new List <GenreFirstModel>();
            var dbGenres = manager.listService.GetAllGenres().ToList();

            for (int i = 0; i < 4 && dbGenres.Count > 0; i++)
            {
                genres.Add(Genre.GetGenreFirstModel(dbGenres.ElementAt(random.Next(dbGenres.Count - 1))));
            }
            List <ListShortModel> lists = new List <ListShortModel>();
            var dbLists = manager.listService.GetAllLists().ToList();

            for (int i = 0; i < 4 && dbLists.Count > 0; i++)
            {
                lists.Add(List.GetListShortModel(dbLists.ElementAt(random.Next(dbLists.Count - 1))));
            }
            result.Authors = authors;
            result.Books   = books;
            result.Genres  = genres;
            result.Lists   = lists;
            return(result);
        }