public IActionResult ChangePageHome(AllAddedBooksViewModel model, int id)
        {
            this.StartUp();
            var returnModel = this.homeService.ChangeActivePage(model, id);

            return(this.View("Index", returnModel));
        }
Example #2
0
        public AllAddedBooksViewModel PreparedPage()
        {
            var model       = new AllAddedBooksViewModel();
            var returnModel = this.GetBooks(model);

            return(returnModel);
        }
        public IActionResult HomeBooksSearch(AllAddedBooksViewModel model)
        {
            this.StartUp();
            var returnModel = this.homeService.GetBooks(model);

            return(this.View("Index", returnModel));
        }
        public IActionResult ChangePageAddedBook(AllAddedBooksViewModel model, int id)
        {
            this.StartUp();

            var returnModel = this.allAddedBooksServices.ChangeActivePage(model, this.userId, id);

            return(this.View("AddedBooks", returnModel));
        }
        public IActionResult AddedBooksSearch(AllAddedBooksViewModel model)
        {
            this.StartUp();

            var returnModel = this.allAddedBooksServices.GetBooks(model, this.userId);

            return(this.View("AddedBooks", returnModel));
        }
        public IActionResult ViewBook(AllAddedBooksViewModel model, string id)
        {
            this.StartUp();
            this.TempData["viewBookId"] = id;
            var returnModel = this.viewBookService.PreparedPage(id);

            return(this.View(returnModel));
        }
        public IActionResult DeleteBook(AllAddedBooksViewModel model, string id)
        {
            this.StartUp();

            this.ViewData["message"] = "Успешно премахната книга";
            var returnModel = this.allAddedBooksServices.DeleteBook(this.userId, model, id);

            return(this.View("AddedBooks", returnModel));
        }
        public AllAddedBooksViewModel DeleteBook(string userId, AllAddedBooksViewModel model, string bookId)
        {
            var deleteBook = this.context.Books.FirstOrDefault(b => b.Id == bookId);

            if (deleteBook != null)
            {
                deleteBook.DeletedOn = DateTime.UtcNow;
                this.context.SaveChanges();
                string result = "Успешно изтрита книга!";
                this.messageService.AddNotificationAtDB(userId, result);
            }

            var returnModel = this.GetBooks(model, userId);

            return(returnModel);
        }
Example #9
0
        public AllAddedBooksViewModel GetBooks(AllAddedBooksViewModel model)
        {
            var bookCatalogNumber = model.SearchBook.CatalogNumber;
            var title             = model.SearchBook.Title;
            var author            = model.SearchBook.Author;
            var genreId           = model.SearchBook.GenreId;
            var sortMethodId      = model.SortMethodId;
            var countBooksOfPage  = model.CountBooksOfPage;
            var currentPage       = model.CurrentPage;

            var books = this.context.Books.Where(b =>
                                                 b.DeletedOn == null)
                        .Select(b => new BookViewModel()
            {
                Author        = b.Author,
                BookId        = b.Id,
                Title         = b.Title,
                GenreName     = b.Genre.Name,
                GenreId       = b.GenreId,
                CatalogNumber = b.CatalogNumber,
                Logo          = b.Logo,
                Review        = b.Review,
            });

            books = this.SelectBooks(bookCatalogNumber, title, author, genreId, books);

            books = this.SortBooks(sortMethodId, books);

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

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

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

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

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

            var returnModel = new AllAddedBooksViewModel()
            {
                Books            = viewBook,
                SearchBook       = searchBook,
                SortMethodId     = sortMethodId,
                Genres           = genres,
                MaxCountPage     = maxCountPage,
                CurrentPage      = currentPage,
                CountBooksOfPage = countBooksOfPage,
            };

            return(returnModel);
        }
Example #10
0
 public AllAddedBooksViewModel ChangeActivePage(AllAddedBooksViewModel model, int newPage)
 {
     model.CurrentPage = newPage;
     return(this.GetBooks(model));
 }