Ejemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            var user = await _accountManager.GetUserByUsernameAsync(User.Identity.Name);

            var topRatedBooks = await _bookManager.GetTopRatedBooks(6);

            var vm = new HomeBooksViewModel()
            {
                Books = new List <GenericBookViewModel>()
            };

            topRatedBooks.ForEach(b => vm.Books.Add(b.MapToGenericViewModel()));

            if (user != null)
            {
                foreach (var book in vm.Books)
                {
                    book.IsBookCheckedout    = _system.IsBookCheckedout(user, book.ISBN);
                    book.AreAllCopiesChecked = await _system.AreAllCopiesCheckedAsync(book.ISBN);

                    book.IsChBooksMaxQuota = _system.IsMaxCheckedoutQuota(user);
                    book.UserStatus        = user.Status.ToString();
                }
            }

            return(View(vm));
        }
Ejemplo n.º 2
0
        private async Task SearchViewModelMapper(SearchViewModel searchVM, IEnumerable <BookViewModel> allBookCopies, User user)
        {
            foreach (var book in allBookCopies)
            {
                if (!searchVM.AllBooks.Any(x => x.ISBN == book.ISBN))
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        book.IsBookCheckedout    = _system.IsBookCheckedout(user, book.ISBN);
                        book.IsChBooksMaxQuota   = _system.IsMaxCheckedoutQuota(user);
                        book.AreAllCopiesChecked = await _system.AreAllCopiesCheckedAsync(book.ISBN);

                        book.UserStatus = user.Status.ToString();
                    }

                    book.BookCopies = await _bookManager.BookCopiesCountAsync(book.ISBN);

                    searchVM.AllBooks.Add(book);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> BookDetails(string id)
        {
            var user = await _accountManager.GetUserByUsernameAsync(User.Identity.Name);

            var books = await _bookManager.GetBooksByIsbnAsync(id);

            var vm = books[0].MapToViewModel();

            foreach (var book in books)
            {
                vm.AllBookCopies.Add(book.MapToCopyViewModel());
            }

            if (User.IsInRole("user"))
            {
                vm.IsBookCheckedout    = _system.IsBookCheckedout(user, vm.ISBN);
                vm.AreAllCopiesChecked = await _system.AreAllCopiesCheckedAsync(vm.ISBN);

                vm.IsChBooksMaxQuota = _system.IsMaxCheckedoutQuota(user);
                vm.UserStatus        = user.Status.ToString();
            }

            return(View(vm));
        }