Esempio n. 1
0
        public IActionResult TakenBooksSearch(TakenBooksViewModel model)
        {
            this.StartUp();
            var returnModel = this.takenBooksService.TakenBooks(model, this.userId);

            return(this.View("TakenBooks", returnModel));
        }
Esempio n. 2
0
        public IActionResult ChangePageTakenBooks(TakenBooksViewModel model, int id)
        {
            this.StartUp();
            var returnModel = this.takenBooksService.ChangeActivePage(model, this.userId, id);

            return(this.View("TakenBooks", returnModel));
        }
        public TakenBooksViewModel PreparedPage(string userId)
        {
            var model       = new TakenBooksViewModel();
            var returnModel = this.GetBooks(model, userId);

            return(returnModel);
        }
        public IActionResult TakenBooksSearch(TakenBooksViewModel model)
        {
            var startUp = this.StartUp();

            if (startUp != null)
            {
                return(startUp);
            }
            var returnModel = this.takenBooksService.TakenBooks(model, this.userId);

            return(this.View("TakenBooks", returnModel));
        }
        private TakenBooksViewModel GetBooks(TakenBooksViewModel model, string userId)
        {
            var title            = model.SearchTakenBook.Title;
            var author           = model.SearchTakenBook.Author;
            var genreId          = model.SearchTakenBook.GenreId;
            var sortMethodId     = model.SortMethodId;
            var countBooksOfPage = model.CountBooksOfPage;
            var currentPage      = model.CurrentPage;
            var catalogNumber    = model.SearchTakenBook.CatalogNumber;

            var getbooks = this.context.GetBooks.Where(b =>
                                                       b.DeletedOn == null &&
                                                       b.UserId == userId)
                           .Select(b => new TakenBookViewModel()
            {
                Author        = b.Book.Author,
                Id            = b.Id,
                Title         = b.Book.Title,
                Genre         = b.Book.Genre.Name,
                GenreId       = b.Book.GenreId,
                CreatedOn     = b.CreatedOn,
                ReturnedOn    = b.ReturnedOn,
                LibraryId     = b.Book.UserId,
                LibraryEmail  = b.Book.User.Email,
                CatalogNumber = b.Book.CatalogNumber,
            });

            getbooks = this.SelectBooks(catalogNumber, title, author, genreId, getbooks);

            getbooks = this.SortBooks(sortMethodId, getbooks);

            var genres = this.genreService.GetAllGenres()
                         .OrderByDescending(x => x.Name).ToList();

            var genre = new GenreListViewModel()
            {
                Id   = null,
                Name = "Избери жанр",
            };

            genres.Add(genre);
            genres.Reverse();
            int maxCountPage = getbooks.Count() / countBooksOfPage;

            if (getbooks.Count() % countBooksOfPage != 0)
            {
                maxCountPage++;
            }

            var viewBook = getbooks.Skip((currentPage - 1) * countBooksOfPage)
                           .Take(countBooksOfPage);
            var searchTakenBook = new TakenBookViewModel()
            {
                Author  = author,
                Title   = title,
                GenreId = genreId,
            };

            var returnModel = new TakenBooksViewModel()
            {
                Books            = getbooks,
                SearchTakenBook  = searchTakenBook,
                SortMethodId     = sortMethodId,
                Genres           = genres,
                MaxCountPage     = maxCountPage,
                CurrentPage      = currentPage,
                CountBooksOfPage = countBooksOfPage,
            };

            return(returnModel);
        }
        public TakenBooksViewModel TakenBooks(TakenBooksViewModel model, string userId)
        {
            var returnModel = this.GetBooks(model, userId);

            return(returnModel);
        }
 public TakenBooksViewModel ChangeActivePage(TakenBooksViewModel model, string userId, int newPage)
 {
     model.CurrentPage = newPage;
     return(this.GetBooks(model, userId));
 }