コード例 #1
0
        public ActionResult Index()
        {
            if (Request.IsAuthenticated)
            {
                var books = uow.BookRepository.Get(filter:
                                                   b => b.UserId.HasValue, orderBy:
                                                   q => q.OrderBy(b => b.ReturnDate))
                            .Take(50);

                var bookListingVM = new BookListingViewModel();

                foreach (Book b in books)
                {
                    if (b.DaysLeft > 0)
                    {
                        bookListingVM.ValidBorrowing.Add(b);
                    }
                    else
                    {
                        bookListingVM.ExpiredBorrowing.Add(b);
                    }
                }

                return(View("IndexAuthenticated", bookListingVM));
            }
            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> All(string orderBy = "Id", string orderDirection = "descending", int page = 1, int pageSize = 4)
        {
            var books = await this.books.AllAsync(orderBy, orderDirection, page, pageSize);

            var allBooks = new BookListingViewModel
            {
                Books       = books,
                TotalBooks  = await this.books.TotalAsync(),
                CurrentPage = page,
                PageSize    = pageSize
            };

            return(View(allBooks));
        }
コード例 #3
0
        public async Task <IActionResult> MyBooks(int page = 1, int pageSize = 4)
        {
            var userId = this.userManager.GetUserId(User);

            var books = await this.books.BooksByCurrentUserAsync(userId, page, pageSize);

            var myBooks = new BookListingViewModel
            {
                Books       = books,
                TotalBooks  = await this.books.TotalByUserAsync(userId),
                CurrentPage = page,
                PageSize    = pageSize
            };

            return(View(myBooks));
        }
コード例 #4
0
        public IActionResult Index()
        {
            List <BookListingViewModel> model = new List <BookListingViewModel>();

            repoBook.GetAll().ToList().ForEach(b => {
                BookListingViewModel book = new BookListingViewModel
                {
                    Id        = b.Id,
                    BookName  = b.Name,
                    Publisher = b.Publisher,
                    ISBN      = b.ISBN
                };
                Author author   = repoAuthor.Get(b.AuthorId);
                book.AuthorName = $"{author.FirstName} {author.LastName}";
                model.Add(book);
            });
            return(View("Index", model));
        }