Пример #1
0
        public async Task <IActionResult> Search(BookSearchViewModel model, string orderBy = "Id", string orderDirection = "descending")
        {
            var searchText = string.IsNullOrEmpty(model.SearchText) ? string.Empty : model.SearchText;

            if (model.PageSize < 4)
            {
                model.PageSize = 4;
            }

            if (model.CurrentPage < 1)
            {
                model.CurrentPage = 1;
            }

            var viewModel = new BookSearchViewModel
            {
                Books       = await this.books.SearchBookAsync(model.SearchIn, searchText, orderBy, orderDirection, model.CurrentPage, model.PageSize),
                SearchIn    = model.SearchIn,
                SearchText  = searchText,
                PageSize    = model.PageSize,
                CurrentPage = model.CurrentPage
            };

            return(View(viewModel));
        }
Пример #2
0
        public ActionResult Index(BookSearchViewModel bookSearchViewModel)
        {
            ViewBag.Message = "Książki";
            var libraryClient = new LibrarySoapClient();
            var bookTitle     = bookSearchViewModel.BookTitle ?? "";

            bookSearchViewModel.Books = libraryClient.GetBooks(bookTitle);
            libraryClient.Close();
            return(View(bookSearchViewModel));
        }
        public ActionResult Index()
        {
            InitializeUserNameSessionVariable();

            var model = new BookSearchViewModel();

            model.Categories = GetCategories();

            return(View(model));
        }
Пример #4
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ViewModel = (BookSearchViewModel)e.Parameter;
            if (ViewModel != null)
            {
                ViewModel.SearchTriggered += ViewModel_SearchTriggered;
            }

            base.OnNavigatedTo(e);
        }
        public static BookSearch ConvertToModel(this BookSearchViewModel viewModel)
        {
            BookSearch model = new BookSearch();

            model.TitleSearch    = viewModel.TitleSearch;
            model.ISBNSearch     = viewModel.ISBNSearch;
            model.AuthorSearch   = viewModel.AuthorSearch;
            model.LanguageSearch = viewModel.LanguageSearch;
            model.GenreSearch    = viewModel.GenreSearch;

            return(model);
        }
Пример #6
0
        public ActionResult EasterCheck(int easterYear)
        {
            var easterDate = ExtraFunctions.API.EasterDateSearch(easterYear);

            var model = new BookSearchViewModel()
            {
                SearchResult   = CheckForCahedBookSearchResult(),
                EasterQuestion = easterYear,
                EasterAnswer   = easterDate.ToShortDateString()
            };

            return(View("BookSearch", model));
        }
Пример #7
0
        public ActionResult FibonacciCheck(int fibonacciNr)
        {
            var isFibonacci = ExtraFunctions.API.IsFibonacci(fibonacciNr);

            var model = new BookSearchViewModel()
            {
                SearchResult      = CheckForCahedBookSearchResult(),
                FibonacciAnswer   = isFibonacci,
                FibonacciQuestion = fibonacciNr
            };

            return(View("BookSearch", model));
        }
Пример #8
0
        //
        // GET: /search/
        public IActionResult Index(string generalSearch, string title, string author, string isbn, string courseName)
        {
            var bookList = new List <Book>();

            //chars to split by
            char[] delimiterChars = { ' ', ',', '.', ':' };

            System.Diagnostics.Debug.WriteLine("Search: " + generalSearch + " Title: " + title + " Author: " + author + " ISBN: " + isbn + " Course:" + courseName);

            if (!String.IsNullOrEmpty(generalSearch))
            {
                string[] words = generalSearch.Split(delimiterChars);
                foreach (string str in words)
                {
                    if (!String.IsNullOrEmpty(str))
                    {
                        bookList = bookList.Union(getBooksByGeneralString(str)).ToList();
                    }
                }
            }


            // To be used for advanced search
            if (!String.IsNullOrEmpty(title))
            {
                bookList = getBooksByTitle(title, bookList);
            }
            if (!String.IsNullOrEmpty(author))
            {
                bookList = getBooksByAuthor(author, bookList);
            }
            if (!String.IsNullOrEmpty(isbn))
            {
                bookList = getBooksByIsbn(isbn, bookList);
            }
            if (!String.IsNullOrEmpty(courseName))
            {
                bookList = getBooksByCourse(courseName, bookList);
            }



            var bookSearchViewModel = new BookSearchViewModel();

            bookSearchViewModel.schools = _context.Schools.Where(a => a.Status == 1).ToList();
            bookSearchViewModel.courses = _context.Courses.ToList();

            bookSearchViewModel.bookList = bookList;

            return(View(bookSearchViewModel));
        }
Пример #9
0
        public IEnumerable <BookSearchViewModel> GetFilteredBooks(DataTablePaginationModel model)
        {
            var books = bookCatalogRepository.GetBooks(GetOrderType(model.iSortCol_0), model.sSortDir_0, model.iDisplayStart, model.iDisplayLength, model.sSearch_2);

            var booksViews = new List <BookSearchViewModel>();

            for (int i = 0; i < books.Count(); i++)
            {
                var bookView = new BookSearchViewModel();
                AutoMapper.Mapper.Map <Book, BookSearchViewModel>(books[i], bookView);
                booksViews.Add(bookView);
            }

            return(booksViews);
        }
Пример #10
0
        public ActionResult BookSearch(string searchString)
        {
            SearchResult searchResult = new SearchResult();

            if (!string.IsNullOrEmpty(searchString))
            {
                searchResult            = BookSearchService.SearchForBooks(searchString);
                Session["searchString"] = searchString;
            }

            var model = new BookSearchViewModel()
            {
                SearchResult = searchResult
            };

            return(View("BookSearch", model));
        }
Пример #11
0
        public async Task <IActionResult> Search([FromQuery] string query = null, [FromQuery] int shelfId = 0)
        {
            var model = new BookSearchViewModel()
            {
                BookList = new List <BookDetailViewModel>(),
                Search   = query,
                ShelfId  = shelfId
            };

            var userId = User.GetUserId();

            model.UserShelves = _context.Shelves
                                .Where(s => !s.IsDeleted && s.CreatedById == userId)
                                .Select(p => new SelectListItem()
            {
                Text = p.Title, Value = p.Id.ToString()
            })
                                .ToList();

            if (string.IsNullOrWhiteSpace(query))
            {
                return(View(model));
            }

            var volumeList = await _bookFinder.Search(query);

            if (volumeList != null)
            {
                foreach (var volume in volumeList)
                {
                    model.BookList.Add(new BookDetailViewModel()
                    {
                        Title         = volume.VolumeInfo.Title,
                        Subtitle      = volume.VolumeInfo.Subtitle,
                        Description   = volume.VolumeInfo.Description,
                        GoogleBookId  = volume.Id,
                        PublishedYear = volume.VolumeInfo.PublishedDate,
                        PublisherName = volume.VolumeInfo.Publisher,
                        Authors       = volume.VolumeInfo.Authors != null ? string.Join(", ", volume.VolumeInfo.Authors) : "",
                        ImageLink     = volume.VolumeInfo.ImageLinks != null ? volume.VolumeInfo.ImageLinks.Thumbnail : "/images/book.jpg"
                    });
                }
            }

            return(View(model));
        }
Пример #12
0
        public JsonResult GetBooks(BookSearchViewModel searchModel)
        {
            int itemPerPage = Int32.Parse(ConfigurationManager.AppSettings["PageSize"]);

            var searchServiceModel = new BookSearchServiceModel()
            {
                Author        = searchModel.Author,
                Description   = searchModel.Description,
                ISBN          = searchModel.ISBN,
                PublishDate   = searchModel.PublishDate,
                Title         = searchModel.Title,
                CategoryId    = searchModel.CategoryId,
                SubcategoryId = searchModel.SubcategoryId,
                ItemPerPage   = itemPerPage,
                PageNumber    = searchModel.PageNumber,
            };

            var findResult = _bookService.Find(searchServiceModel);
            var booksList  = findResult.Books.Select(b => new BookViewModel
            {
                Id          = b.Id,
                ISBN        = b.ISBN,
                Title       = b.Title,
                PublishDate = b.PublishDate.ToShortDateString(),
                FrontCover  = Url.Content(b.FrontCover),
                Authors     = b.Authors.Select(a =>
                                               string.Join(" ", a.FirstName, (a.MiddleName ?? ""), a.LastName)),
                Categories = b.SubCategories.Select(sc => new CategoryViewModel
                {
                    Category    = sc.Category.Name,
                    SubCategory = sc.Name
                }),
                Description = b.Description,
                BookLink    = Url.RouteUrl("Default", new { controller = "BookDetails", action = "Show", id = b.Id })
            }).ToList();


            var bookListViewModel = new BooksListViewModel()
            {
                NumberOfPages = (int)Math.Ceiling((double)findResult.NumberOfBooks / itemPerPage),
                Books         = booksList,
            };

            return(Json(bookListViewModel, JsonRequestBehavior.AllowGet));
        }
Пример #13
0
        public async Task <BookSearchViewModel> BookSearchAsync(string bookGenre, string bookAuthor,
                                                                string bookPublisher, string searchString)
        {
            var genreQuery = bookRepository.GetItems()
                             .OrderBy(b => b.Genre)
                             .Select(b => b.Genre);

            var authorQuery = bookRepository.GetItems()
                              .OrderBy(b => b.Author)
                              .Select(b => b.Author);

            var publisherQuery = bookRepository.GetItems()
                                 .OrderBy(b => b.Publisher)
                                 .Select(b => b.Publisher);

            var books = bookRepository.GetItems();

            if (!string.IsNullOrEmpty(searchString))
            {
                books = books.Where(s => s.Name.Contains(searchString));
            }
            if (!string.IsNullOrEmpty(bookGenre))
            {
                books = books.Where(x => x.Genre == bookGenre);
            }
            if (!string.IsNullOrEmpty(bookAuthor))
            {
                books = books.Where(x => x.Author == bookAuthor);
            }
            if (!string.IsNullOrEmpty(bookPublisher))
            {
                books = books.Where(x => x.Publisher == bookPublisher);
            }

            var bookSearchVM = new BookSearchViewModel
            {
                Genres    = new SelectList(await genreQuery.Distinct().ToListAsync()),
                Authors   = new SelectList(await authorQuery.Distinct().ToListAsync()),
                Publisher = new SelectList(await publisherQuery.Distinct().ToListAsync()),
                Books     = await books.OrderBy(b => b.Name).ToListAsync()
            };

            return(bookSearchVM);
        }
        public static BookSearchViewModel MapBookSearch(BookDTO bookDTO, IHit <BookDTO> hit)
        {
            var bookSearchViewModel = new BookSearchViewModel()
            {
                Id         = hit.Id,
                Ean        = bookDTO.Ean,
                Title      = bookDTO.Title,
                Highlights = string.Empty,
                Score      = hit.Score.Value
            };


            int i          = 0;
            var highlights = hit.Highlights["abstract"].Highlights;

            foreach (var highlight in highlights)
            {
                bookSearchViewModel.Highlights += $"{++i}. '{highlight.TrimStart(',').Trim()}'<br/>";
            }

            return(bookSearchViewModel);
        }