예제 #1
0
        // GET: Books

        public ActionResult Index(string searchString, int page = 1)
        {
            try
            {
                var books    = db.Books.AsQueryable();
                int pageSize = 10;
                if (!string.IsNullOrEmpty(searchString))
                {
                    books = (db.Books.Include(b => b.Author).Include(b => b.CountryPublished).Where(n => n.Title.Contains(searchString) || n.Author.FullName.Contains(searchString)));
                    if (!books.Any())
                    {
                        return(PartialView("SearchViewNotFound", searchString));
                    }
                }
                BooksListModel model = new BooksListModel
                {
                    BooksList = BookRelase.GetBookResult(books)
                };

                if (page > model.BooksList.ToPagedList(page, pageSize).PageCount)
                {
                    return(RedirectToAction("Index"));
                }
                return(Request.IsAjaxRequest() ? (ActionResult)PartialView("IndexPartial", model.BooksList.ToPagedList(page, pageSize)) :
                       View(model.BooksList.ToPagedList(page, pageSize)));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
예제 #2
0
        // GET: Admin
        public ActionResult Index(string searchString, string sortOption, int page = 1)
        {
            try
            {
                int pageSize = 5;
                var books    = db.Books.ToList();
                if (!string.IsNullOrEmpty(searchString))
                {
                    books = (db.Books.Include(b => b.Author).Include(b => b.CountryPublished).Where(n => n.Title.Contains(searchString) || n.Author.FullName.Contains(searchString))).ToList();
                    if (!books.Any())
                    {
                        //return Content("This book is not found <a href='~Admin/Index'>Go</a> ");
                        return(PartialView("BookNot", searchString));
                    }
                }
                BooksListModel model = new BooksListModel
                {
                    BooksList = BookRelase.GetBookResult(books)
                };

                switch (sortOption)
                {
                case "Title_ASC": model.BooksList = model.BooksList.OrderBy(n => n.Title).ToList(); break;

                case "Title_DESC": model.BooksList = model.BooksList.OrderByDescending(n => n.Title).ToList(); break;

                case "Price_ASC": model.BooksList = model.BooksList.OrderBy(n => n.totalPrice).ToList(); break;

                case "Price_DESC": model.BooksList = model.BooksList.OrderByDescending(n => n.totalPrice).ToList(); break;

                case "Author_ASC": model.BooksList = model.BooksList.OrderBy(n => n.Author.FullName).ToList(); break;

                case "Author_DESC": model.BooksList = model.BooksList.OrderByDescending(n => n.Author.FullName).ToList(); break;

                case "PageCount_ASC": model.BooksList = model.BooksList.OrderBy(n => n.PagesCount).ToList(); break;

                case "PageCount_DESC": model.BooksList = model.BooksList.OrderByDescending(n => n.PagesCount).ToList(); break;

                case "Country_ASC": model.BooksList = model.BooksList.OrderBy(n => n.CountryPublished.CountryName).ToList(); break;

                case "Country_DESC": model.BooksList = model.BooksList.OrderByDescending(n => n.CountryPublished.CountryName).ToList(); break;

                default: model.BooksList = model.BooksList.OrderBy(n => n.Id).ToList(); break;
                }
                if (page > model.BooksList.ToPagedList(page, pageSize).PageCount)
                {
                    return(RedirectToAction("Index"));
                }
                return(Request.IsAjaxRequest() ? (ActionResult)PartialView("IndexPartial", model.BooksList.ToPagedList(page, pageSize)) :
                       View(model.BooksList.ToPagedList(page, pageSize)));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
예제 #3
0
        public ActionResult Index()
        {
            var            books = db.Books.ToList();
            BooksListModel model = new BooksListModel
            {
                BooksList = BookRelase.GetBookResult(books)
            };
            Random rnd = new Random();

            return(View(model.BooksList.OrderBy(n => rnd.Next()).Take(5)));
        }
예제 #4
0
        public ActionResult Index(string search)
        {
            var isbnFiltered = ISBNFilter.Filter(search);
            var books        = new BookRepository().SearchFor(book => book.ISBN.Contains(isbnFiltered) || book.Title.Contains(search)).ToList();
            var model        = new BooksListModel
            {
                Books = GetBooksListModels(books)
            };

            return(View(model));
        }
예제 #5
0
        public ActionResult Index(BooksListSuccessMessage message = BooksListSuccessMessage.None)
        {
            var books = new BookRepository().GetAll();
            var model = new BooksListModel
            {
                Books = GetBooksListModels(books)
            };

            if (message != BooksListSuccessMessage.None)
            {
                model.SuccessMessage = message.GetDescriptionAttributeValue();
            }
            return(View(model));
        }
예제 #6
0
        public BooksListModel GetBooksByAuthor(string authorName)
        {
            try
            {
                BookService bookService = new BookService();

                List <Book>    dbBooks = bookService.GetByAuthor(authorName);
                BooksListModel result  = new BooksListModel(dbBooks);

                return(result);
            }
            catch (Exception ex)
            {
                BooksListModel result = new BooksListModel();
                result.ErrorMessage = ex.GetBaseException().Message;
                return(result);
            }
        }
예제 #7
0
        public BooksListModel GetBorrowedBooksByReader(int readerID)
        {
            try
            {
                BookService bookService = new BookService();

                List <Book>    dbBooks = bookService.GetBorrowedBooksByReader(readerID);
                BooksListModel result  = new BooksListModel(dbBooks);

                return(result);
            }
            catch (Exception ex)
            {
                BooksListModel result = new BooksListModel();
                result.ErrorMessage = $"Could not get borrowed books by reader {readerID}. Error message is: {ex.GetBaseException().Message}";
                return(result);
            }
        }
예제 #8
0
        public BooksListModel GetNotReturnedBooks()
        {
            try
            {
                BookService bookService = new BookService();

                List <Book>    dbBooks = bookService.GetNotReturnedBooks();
                BooksListModel result  = new BooksListModel(dbBooks);

                return(result);
            }
            catch (Exception ex)
            {
                BooksListModel result = new BooksListModel();
                result.ErrorMessage = $"Could not retrieve not returned books. Error message is: {ex.GetBaseException().Message}";
                return(result);
            }
        }