public BookViewModel GetBooksByPage(int page, int pages, SearchBookViewModel search) { IQueryable <Book> query = _bookRepository.GetAllBooks(); BookViewModel model = new BookViewModel(); if (!string.IsNullOrEmpty(search.Title)) { query = query.Where(c => c.Title.Contains(search.Title)).AsQueryable(); } if (!string.IsNullOrEmpty(search.Author)) { query = query.Where(c => c.Author.LastName.Contains(search.Author)).AsQueryable(); } model.Books = query .OrderBy(c => c.Title) .Skip((page - 1) * pages) .Take(pages) .Select(c => new BookItemViewModel { Id = c.Id, Title = c.Title, Pages = c.Pages, Author = c.Author.LastName }).AsQueryable(); model.TotalPages = (int)Math.Ceiling((double)query.Count() / pages); model.CurrentPage = page; model.Search = search; model.Pages = pages; return(model); }
public ResponseResults <BookViewModel> GetBooks(SearchBookViewModel searchParam) { var response = new ResponseResults <BookViewModel> { IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY }; try { var models = UnitOfWork.BookRepository.GetBooks(searchParam); response.ViewModels = models.ToViewModel <BookEntityModel, BookViewModel>().ToList(); if (!string.IsNullOrWhiteSpace(searchParam.UserName)) { var user = UnitOfWork.UserRepository.FindByUserName(searchParam.UserName); var demandedBookLookUp = UnitOfWork.UserDemandRepository.GetMany(o => o.UserId == user.Id).Select(o => o.BookId).ToList(); response.ViewModels.ForEach(o => o.IsRequested = demandedBookLookUp.Contains(o.Id)); } if (response.ViewModels.Count <= 0) { response.Message = AppMessages.NO_RECORD_FOUND; } } catch (Exception ex) { response.IsSucceed = false; response.Message = ex.Message; } return(response); }
public async Task <ActionResult> Search(string BookGenre, string SearchString) { try { _logger.LogInformation("Opening Search Screen .."); SearchBookViewModel sm = new SearchBookViewModel(); if (String.IsNullOrEmpty(SearchString)) { //sm.Book = new List<BookViewModel>(); sm.Book = await _bookService.GetBooks(); // _db.Books.ToList(); return(View("SearchResult", sm)); } if (!String.IsNullOrEmpty(SearchString)) { sm.Book = await _bookService.GetBooksFilter(SearchString); // _db.Books.Where(a => a.Title.Contains(SearchString)).ToList(); } //int i = 1; int j = 0; //int k = i / j; return(View("SearchResult", sm)); } catch (Exception ex) { _logger.LogError(ex, "Error running book search filter {searchstring}", SearchString); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") { return(RedirectToAction("Error", "Common", new { errorMessage = ex.Message.ToString() })); } return(RedirectToAction("Error", "Common", new { errorMessage = "Error running searching. Please contact support." })); } }
public async Task <PartialViewResult> Search(string query, int?page) { var input = new SearchInput { Query = query, PageIndex = page - 1 ?? 0, PageSize = GetDefaultPageSize() }; var output = await _searchservice.SearchAsync(input); var results = new PagedList <IHit <BookIndexItem> >(output.Hits, input.PageIndex, input.PageSize, (int)output.Total); var model = new SearchBookViewModel { Query = query, Took = output.Took, Results = results, Suggestions = output.Suggest, IsShownResult = output.Hits.Any(), IsShownSuggest = output.Suggest.Values.Any(x => x.Any(y => y.Options.Any())), IsShownPagination = results.PageCount > 1 }; return(PartialView("_SearchResult", model)); }
public async Task <ActionResult> SearchAsync(SearchBookViewModel searchBookViewModel) { HttpClient client = new HttpClient { BaseAddress = new Uri(_serviceUri) }; try { var bookViewModel = new SearchBookViewModel(); HttpResponseMessage response = await client.GetAsync("api/books/search/" + searchBookViewModel.SearchField + (string.IsNullOrEmpty(searchBookViewModel.Subject) ? null : "/" + searchBookViewModel.Subject)).ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.OK) { bookViewModel.Books = await response.Content.ReadAsAsync <List <Book> >().ConfigureAwait(false); } else if (response.StatusCode == HttpStatusCode.NotFound) { ModelState.AddModelError("", "No books found."); return(View("Index")); } return(View("Index", bookViewModel)); } catch (HttpRequestException e) { ModelState.AddModelError("Error", "Error: " + e.Message); return(View("Index")); } }
public IEnumerable <Book> Post(SearchBookViewModel oSearch) { // var books = _bookRepository.GetAllBooks().AsEnumerable(); var books = from r in _bookRepository.GetAllBooks() where (r.Name == oSearch.Name || oSearch.Name.Length == 0) && (r.ISBN == oSearch.ISBN || oSearch.ISBN.Length == 0) && (r.Description == oSearch.Description || oSearch.Description.Length == 0) && (r.Author == oSearch.Author || oSearch.Author.Length == 0) select r; return(books); }
public ActionResult GetSearchBooksDetails(SearchBookViewModel oSearch) { // var books = _bookRepository.GetAllBooks().AsEnumerable(); var books = from r in _bookRepository.GetAllBooks() where (r.Name == oSearch.Name || oSearch.Name.Length == 0) && (r.ISBN == oSearch.ISBN || oSearch.ISBN.Length == 0) && (r.Description == oSearch.Description || oSearch.Description.Length == 0) && (r.Author == oSearch.Author || oSearch.Author.Length == 0) select r; return(Json(books, JsonRequestBehavior.AllowGet)); }
public void GetBooks_ByInvalidSearchParam_Returns_NoRecords() { //Arrange var userName = UserRepositoryGenerator.GetDataCollection()[0].UserName; var author = "Author1"; var searchParam = new SearchBookViewModel { UserName = userName, Author = author }; //Act var response = domainService.GetBooks(searchParam); //Assert Assert.IsTrue(response.ViewModels.Count == 0); }
public async Task <ActionResult> Search(SearchBookViewModel svm) { SearchBookViewModel sm = new SearchBookViewModel(); try { sm.Book = await _bookService.GetBooksFilter(svm.SearchString); // _db.Books.Where(a => a.Title.Contains(svm.SearchString)).ToList(); return(View(sm)); } catch { return(RedirectToPage("Error")); } }
public ActionResult Search(SearchBookViewModel model) { if (ModelState.IsValid) { string booktype = Convert.ToString(model.BookType); var db = new SchoolBookDbContext(); IEnumerable <Book> books = db.Books .Where(x => x.Type.Name.Contains(booktype) || x.Type.BookCategory.Name.Contains(booktype)) .OrderByDescending(x => x.CreatedOn) .ToList(); return(PartialView("_SearchBook", books)); } return(Json("Error Message")); }
public void GetBooks_ByValidSearchParam_Returns_Records() { //Arrange var userName = UserRepositoryGenerator.GetDataCollection()[0].UserName; var author = BookRepositoryGenerator.GetDataCollection()[0].Authors.FirstOrDefault(); var searchParam = new SearchBookViewModel { UserName = userName, Author = author }; //Act var response = domainService.GetBooks(searchParam); //Assert Assert.IsTrue(response.IsSucceed); Assert.IsTrue(response.ViewModels.Count > 0); }
public List <BookEntityModel> GetBooks(SearchBookViewModel searchParam) { var query = DbSet.AsQueryable(); if (!string.IsNullOrWhiteSpace(searchParam.Title)) { query = query.Where(o => o.Title.ToLower().Trim().Contains(searchParam.Title.ToLower().Trim())); } if (!string.IsNullOrWhiteSpace(searchParam.Author)) { query = query.Where(o => o.Authors.Any(s => s.StartsWith(searchParam.Author.Trim()))); } return(query.ToList()); }
public async Task GetBooks_InValidSearchParam_Returns_NoRecords() { // Arrange var userName = UserManagerGenerator.GetDataCollection()[0].UserName; var author = "Author1"; var searchParam = new SearchBookViewModel { UserName = userName, Author = author }; // Act var response = controller.Get(searchParam); dynamic responseContent = await response.Content.ReadAsAsync <ExpandoObject>(); var selectedItems = responseContent.ViewModels; // Assert Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); Assert.IsTrue(selectedItems.Count == 0); }
public void GetBooks_ByInvalidSearchParam_Check_AlreadyRequested() { //Arrange var bookId = UserDemandRepositoryGenerator.GetDataCollection()[0].BookId; var userId = UserDemandRepositoryGenerator.GetDataCollection()[0].UserId; var userName = UserRepositoryGenerator.GetDataCollection().FirstOrDefault(o => o.Id == userId).UserName; var author = BookRepositoryGenerator.GetDataCollection().FirstOrDefault(o => o.Id == bookId).Authors.FirstOrDefault(); var searchParam = new SearchBookViewModel { UserName = userName, Author = author }; //Act var response = domainService.GetBooks(searchParam); //Assert Assert.IsTrue(response.IsSucceed); Assert.IsTrue(response.ViewModels.FirstOrDefault(o => o.Id == bookId).IsRequested); }
public ActionResult BookSearch(SearchBookViewModel searchBookViewModel) { var filters = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(searchBookViewModel.Name)) { filters.Add("Name", searchBookViewModel.Name); } if (searchBookViewModel.ISBN != 0) { filters.Add("ISBN", searchBookViewModel.ISBN); } if (!string.IsNullOrEmpty(searchBookViewModel.Author)) { filters.Add("Author", searchBookViewModel.Author); } var books = _bookService.GetAvailableBooksBySearchFilter(filters); return(View("ShowBooks", books)); }
public IActionResult SearchBook(string keyword) { SearchBookViewModel model = _searchBook.GetSearchResult(keyword); return(View(model)); }
public ActionResult Search() { SearchBookViewModel model = new SearchBookViewModel(); return(View(model)); }
public HttpResponseMessage Get([FromUri] SearchBookViewModel searchParam) { var response = searchBookService.GetBooks(searchParam); return(Request.CreateResponse(HttpStatusCode.OK, new { response.ViewModels, message = response.Message })); }
public ActionResult Index(int page = 1, int pages = 10, SearchBookViewModel search = null) { return(View(_bookProvider.GetBooksByPage(page, pages, search))); }
public MainPage() { InitializeComponent(); BindingContext = new SearchBookViewModel(); }