public IHttpActionResult Get([FromUri] BookSearch data) { // search for book by title, author, or genre. // bind author and genre params to book search // fromuri = force web api to read complex data type (object) var db = new LibraryContext(); var bookQuery = db.Books.Include(i => i.Author).Include(i => i.Genre); // if string has any params from BookSearch class, return them. if (!String.IsNullOrEmpty(data.Title)) { bookQuery = bookQuery.Where(w => w.Title.Contains(data.Title)); } if (!String.IsNullOrEmpty(data.Author)) { bookQuery = bookQuery.Where(w => w.Author.Name.Contains(data.Author)); } if (!String.IsNullOrEmpty(data.Genre)) { bookQuery = bookQuery.Where(w => w.Genre.Name.Contains(data.Genre)); } var results = bookQuery.ToList(); if (results.Count == 0) { return(NotFound()); } else { return(Ok(results)); } }
public PagedResponse <BookDto> Execute(BookSearch search) { var query = _context.Books .Include(x => x.Title) .ThenInclude(x => x.TitleAuthors) .ThenInclude(x => x.Author) .Include(x => x.Title) .ThenInclude(x => x.Publisher) .Include(x => x.Title) .ThenInclude(x => x.Category) .Include(x => x.Title) .ThenInclude(x => x.Prices) .DefaultFilter(search); if (search.TitleIds.Count() > 0) { query = query.Where(x => search.TitleIds.Contains(x.TitleId)); } if (search.SerialNumber.HasValue) { query = query.Where(x => x.SerialNumber.ToString().ToLower().Contains(search.SerialNumber.ToString().ToLower())); } return(query.Paged <BookDto, Domain.Book>(search, _mapper)); }
private void BookSearch_Click(object sender, RoutedEventArgs e) { List <Book> books = ProcessBookFile("books.csv"); BookSearch search = new BookSearch(books); search.ShowDialog(); }
public ActionResult BookSearch(string query) { BookSearch bookSearch = new BookSearch(); List <BookModel> bookModels = bookSearch.Search(query); return(View(bookModels)); }
private void updateButton_Click(object sender, RoutedEventArgs e) { try { if (iSBNTextBox.Text == "") { throw new Exception("Please enter the ISBN of the book you would like to update."); } BookSearch search = new BookSearch(books, people, iSBNTextBox.Text.Trim()); search.ISBNSearch(); if (search.FoundBooks.Count == 0) { throw new Exception("No book was found with that ISBN."); } //The found book will now be placed into a bookUpdater object for the updating process BookUpdater updater = new BookUpdater(books, people, logs, search.FoundBooks[0]); //Load the bookUpdatePage Reset(); this.NavigationService.Navigate(new UpdateBookPage(updater)); } catch (Exception ex) { errorLabel.Content = ErrorHandler.InnermostExceptionMessage(ex); } }
public List <Book> FindBooks(BookSearch entity) { List <Book> books = _bookRepository.GetAll(); if (!String.IsNullOrEmpty(entity.TitleSearch)) { books = books.Where(x => x.Title.Contains(entity.TitleSearch)).ToList(); } if (!String.IsNullOrEmpty(entity.ISBNSearch)) { books = books.Where(x => x.ISBN.Contains(entity.ISBNSearch)).ToList(); } if (entity.AuthorSearch != null) { books = books.Where(x => x.Authors.Any(y => y.Id == entity.AuthorSearch)).ToList(); } if (entity.LanguageSearch != null) { books = books.Where(x => x.Language.Id == entity.LanguageSearch).ToList(); } if (entity.GenreSearch != null) { books = books.Where(x => x.Genre != null).Where(x => x.Genre.Id == entity.GenreSearch).ToList(); } return(books); }
public List <Book> BuscarLivros(BookSearch busca, string path = "") { List <Book> books = Repository.Data(path); books = books.Where(x => (string.IsNullOrWhiteSpace(busca.Name) || RemoveDiacritics(x.Name).Contains(RemoveDiacritics(busca.Name))) && (string.IsNullOrWhiteSpace(busca.Author) || RemoveDiacritics(x.Specifications.Author).Contains(RemoveDiacritics(busca.Author))) && (string.IsNullOrWhiteSpace(busca.Illustrator) || x.Specifications.Illustrator.Any(i => RemoveDiacritics(i).Contains(RemoveDiacritics(busca.Illustrator)))) && (string.IsNullOrWhiteSpace(busca.Genres) || x.Specifications.Genres.Any(g => RemoveDiacritics(g).Contains(RemoveDiacritics(busca.Genres)))) && (busca.MinPrice == null || x.Price >= busca.MinPrice) && (busca.MaxPrice == null || x.Price <= busca.MaxPrice) && (busca.MinPage == null || x.Specifications.PageCount >= busca.MinPage) && (busca.MaxPage == null || x.Specifications.PageCount <= busca.MaxPage) ).ToList(); books.ForEach(x => x.ShippingFee = Math.Round(x.Price * 0.2, 2)); if (!string.IsNullOrWhiteSpace(busca.Order)) { if (busca.Order == "asc") { books = books.OrderBy(x => x.Price).ToList(); } else if (busca.Order == "desc") { books = books.OrderByDescending(x => x.Price).ToList(); } } return(books); }
public void SearchTest() { BookSearch bookSearch = new BookSearch(); var result = bookSearch.Search("Spinning Silver"); Assert.AreEqual(result != null, true); }
//search public async Task <List <BookSearch> > SearchBook(BookSearch searchdata) { var sql = @"SELECT bd.BOOK_ID AS BookID,bc.BOOK_CLASS_NAME AS BookClassId,bd.BOOK_NAME AS BookName, CONVERT(varchar, bd.BOOK_BOUGHT_DATE, 111) AS BoughtDate, bcd.CODE_NAME AS BookStatusId, mm.USER_ENAME AS BookKeeperId FROM BOOK_DATA bd INNER JOIN BOOK_CLASS bc ON bd.BOOK_CLASS_ID = bc.BOOK_CLASS_ID INNER JOIN BOOK_CODE bcd ON bd.BOOK_STATUS = bcd.CODE_ID AND bcd.CODE_TYPE = 'BOOK_STATUS' LEFT OUTER JOIN MEMBER_M mm ON bd.BOOK_KEEPER = mm.[USER_ID] WHERE(bd.BOOK_CLASS_ID = @BookClassId OR @BookClassId = '') AND (LOWER(bd.BOOK_NAME) LIKE ('%'+LOWER(@BookName)+'%') OR @BookName = '') AND (bcd.CODE_ID = @BookStatusId OR @BookStatusId = '') AND (mm.[USER_ID] = @BookKeeperId OR @BookKeeperId = '') ORDER BY bd.CREATE_DATE DESC" ; using (SqlConnection conn = new SqlConnection(this.GetDBConnectionString())) { var SearchList = await conn.QueryAsync <BookSearch>(sql, new { BookClassId = searchdata.BookClassId == null ? string.Empty : searchdata.BookClassId, BookName = searchdata.BookName == null ? string.Empty : searchdata.BookName, BookStatusId = searchdata.BookStatusId == null ? string.Empty : searchdata.BookStatusId, BookKeeperId = searchdata.BookKeeperId == null ? string.Empty : searchdata.BookKeeperId }); return(SearchList.ToList()); } }
public PageResponse <BookDTO> Execute(BookSearch request) { var query = _unitOfWork.Book.GetAll(); if (request.MinPrice.HasValue) { query = query.Where(d => d.Price >= request.MinPrice); } if (request.MaxPrice.HasValue) { query = query.Where(d => d.Price <= request.MaxPrice); } if (request.MinPages.HasValue) { query = query.Where(d => d.Pages >= request.MinPages); } if (request.MaxPages.HasValue) { query = query.Where(d => d.Pages <= request.MaxPages); } if (request.Title != null) { var keyword = request.Title.ToLower(); query = query.Where(d => d.Title.ToLower().Contains(keyword)); } if (request.CategoryId != null) { query = query.Where(d => d.CategoryId == request.CategoryId); } if (request.AuthorId != null) { query = query.Where(d => d.AuthorId == request.AuthorId); } var totalCount = query.Count(); query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage); var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage); var response = new PageResponse <BookDTO> { CurrentPage = request.PageNumber, TotalCount = totalCount, PageCount = pagesCount, Data = query.Select(d => new BookDTO() { Id = d.Id, Title = d.Title, Price = d.Price, Description = d.Description, Pages = d.Pages, CategoryName = d.Category.Name, AuthorName = d.Author.FullName, ImageUrl = d.Image }) }; return(response); }
public SearchResultDTO Search(string term, int?userId) { term = term.Trim(); if (String.IsNullOrWhiteSpace(term) || term.Length < 3) { //return empty result return(new SearchResultDTO() { Id = -1, Results = new SearchResultEntryDTO[0], SearchTerm = null }); } using (var db = new SDCContext()) { //simple stuff: //return books that contain the term in their title. UserProfile profile = null; if (userId != null) { profile = db.UserProfiles.FirstOrDefault(p => p.UserId == (int)userId); } var booksResult = (from b in db.Books where b.Shelf.IsVisible && b.Title.Contains(term) select new SearchResultBookDTO() { Id = b.Id, OwnerId = b.Shelf.Owner.UserId, OwnerUserName = b.Shelf.Owner.UserName, Title = b.Title, Authors = b.Authors.Select(a => new AuthorDTO() { Id = a.Id, Name = a.Name }).ToList() }).ToArray(); BookSearch search = new BookSearch() { Date = DateTime.Now, Term = term, User = profile }; db.BookSearches.Add(search); return(new SearchResultDTO() { Id = search.Id, Results = booksResult, SearchTerm = term }); } }
public void TestePaginas(int minPag, int maxPag, int count) { BookSearch busca = new BookSearch(null, null, null, null, minPag, maxPag, null, null, null); var resultado = BookService.BuscarLivros(busca, path); Assert.AreEqual(count, resultado.Count); }
public void TesteGenero(string genre, int count) { BookSearch busca = new BookSearch(null, null, null, null, null, null, null, genre, null); var resultado = BookService.BuscarLivros(busca, path); Assert.AreEqual(count, resultado.Count); }
public void TesteIlustrador(string illustrator, int count) { BookSearch busca = new BookSearch(null, null, null, null, null, null, illustrator, null, null); var resultado = BookService.BuscarLivros(busca, path); Assert.AreEqual(count, resultado.Count); }
public void TestePreco(double minPrice, double maxPrice, int count) { BookSearch busca = new BookSearch(null, minPrice, maxPrice, null, null, null, null, null, null); var resultado = BookService.BuscarLivros(busca, path); Assert.AreEqual(count, resultado.Count); }
public IActionResult Get( [FromQuery] BookSearch search, [FromServices] IGetBooksQuery query) { var result = _executor.ExecuteQuery(query, search); return(Ok(result)); }
public static void main(string[] args) { BookSearch bs = new BookSearch(); BookSearchProxy pbs; pbs = new BookSearchProxy(bs); Book b1 = pbs.getBook("1"); System.Console.WriteLine("==============="); Book b2 = pbs.getBook("2"); }
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); }
public ActionResult Search(BookSearch searchBook) { var result = db.Books.AsQueryable(); if (searchBook != null) { if (!string.IsNullOrEmpty(searchBook.BookTitle)) { result = result.Where(t => t.BookTitle.Contains(searchBook.BookTitle)); } if (!string.IsNullOrEmpty(searchBook.AuthorName)) { result = result.Where(t => t.AuthorName == searchBook.AuthorName); } /*if (!enum.(searchBook.Genre)) * { * result = result.Where(t => t.Genre == searchBook.Genre); * } * * * if (searchBook.GenreType.) * { * result = result.Where(t => t.GenreType == searchBook.GenreType); * }*/ //you have an extra if statement here in case the result is null to redirect to Create page } return(View("Index", result.OrderByDescending(t => t.AuthorName))); /* var books = from b in db.Books * select b; * if(!String.IsNullOrEmpty(BookSearchModel)) * { * books = books.Where(k => k.BookTitle.Contains(BookSearchModel)); * } * if (!String.IsNullOrEmpty(authorSearch)) * { * books = books.Where(k => k.AuthorName.Contains(authorSearch)); * } * if(books.ToList().Count == 0) * { * //google api search * // or redirect to add..do you want to add book * * * return RedirectToAction("Create"); */ }
public SearchInBookPageViewModel( INavigationService navigationService, IBookRepository bookRepository, SearchInBookController searchController, IBusyIndicatorManager busyIndicatorManager, BookSearch bookSearch) { _navigationService = navigationService; _bookRepository = bookRepository; _searchController = searchController; _busyIndicatorManager = busyIndicatorManager; _bookSearch = bookSearch; }
public PagedResponse <BookDto> Execute(BookSearch search) { var query = _context.Books.Include(x => x.Publisher) .Include(x => x.BookAuthors) .ThenInclude(x => x.Author) .AsQueryable(); if (!string.IsNullOrEmpty(search.Title) || !string.IsNullOrWhiteSpace(search.Title)) { query = query.Where(x => x.Title.ToLower().Contains(search.Title.ToLower())); } if (search.MinPrice != 0) { query = query.Where(x => x.Price >= search.MinPrice); } if (search.MaxPrice != 0) { query = query.Where(x => x.Price <= search.MaxPrice); } var skipCount = search.PerPage * (search.Page - 1); var response = new PagedResponse <BookDto> { TotalCount = query.Count(), CurrentPage = search.Page, ItemsPerPage = search.PerPage, Items = query.Skip(skipCount) .Take(search.PerPage) .Select(m => new BookDto { Id = m.Id, Title = m.Title, Year = m.Year, // GenreName = m.Genre.Name, Description = m.Description, Price = m.Price, PublisherName = m.Publisher.Name, BookAuthors = m.BookAuthors.Select(ma => new BookAuthorDto { Id = ma.AuthorId, Year = ma.Book.Year, Name = ma.Author.FirstName, Title = ma.Book.Title, }) }) }; return(response); }
private void searchButton_Click(object sender, RoutedEventArgs e) { try { //Searchs for books and lists matches below to aid updating BookSearch search = new BookSearch(books, people, searchTextBox.Text.Trim()); search.SearchAllFields(); booksListBox.DataContext = search.FoundBooks; } catch (Exception ex) { errorLabel.Content = ErrorHandler.InnermostExceptionMessage(ex); } }
private static void Main(string[] args) { Console.WriteLine("\n------------------------------------------------------------------------"); string isbn = "0071807993"; var output = BookSearch.SearchISBN(isbn); var result = output.Result; Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Book Name: \t" + result.VolumeInfo.Title); Console.WriteLine("Author: \t" + result.VolumeInfo.Authors.FirstOrDefault()); Console.WriteLine("Publisher: \t" + result.VolumeInfo.Publisher); Console.WriteLine("------------------------------------------------------------------------"); }
public SearchInBookResultItemDataModel ToDataModel( BookSearchResult searchResult, string queryString, string bookId) { var query = BookSearch.PrepareQuery(queryString); var item = new SearchInBookResultItemDataModel(); if (searchResult.PreviousContext.Any()) { item.TokenId = searchResult.PreviousContext[0].ID; } else { item.TokenId = searchResult.SearchResult[0].ID; } item.BookId = bookId; var firstWord = query.First(); var lastWord = query.Last(); var firstToken = searchResult.SearchResult.First(); var lastToken = searchResult.SearchResult.Last(); var beforeWords = searchResult.PreviousContext.Select(r => r.Text).ToList(); var afterWords = searchResult.NextContext.Select(r => r.Text).ToList(); var intermediateWords = searchResult.SearchResult.Skip(1).Take(searchResult.SearchResult.Count - 2).Select(r => r.Text).ToList(); var firstWordIndex = firstToken.Text.IndexOf(firstWord, StringComparison.InvariantCultureIgnoreCase); beforeWords.Add(firstToken.Text.Substring(0, firstWordIndex)); intermediateWords.Insert(0, firstToken.Text.Substring(firstWordIndex, firstWord.Length)); var lastWordIndex = lastToken.Text.IndexOf(lastWord, StringComparison.InvariantCultureIgnoreCase); afterWords.Insert(0, lastToken.Text.Substring(lastWordIndex + lastWord.Length)); if (query.Count > 1) { intermediateWords.Add(lastToken.Text.Substring(lastWordIndex, lastWord.Length)); } item.TextBefore = string.Join(" ", beforeWords); item.SearchedText = string.Join(" ", intermediateWords); item.TextAfter = string.Join(" ", afterWords); return(item); }
public IList <BooksList> BookSearch(BookSearch model) { try { DynamicParameters parameters = new DynamicParameters(); parameters.Add("@SearchValue", model.SearchValue); parameters.Add("@SearchId", model.SearchId); IList <BooksList> list = SqlMapper.Query <BooksList>(con, "sp_BookSearch", param: parameters, commandType: CommandType.StoredProcedure).ToList(); return(list); } catch (Exception ex) { throw ex; } }
public IHttpActionResult GetMerchandise(GetRequest data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BookInfo[] books = BookSearch.BookSearchWithMerchandiseId(data.MerchandiseId); if (books.Length == 0) { return(BadRequest("No Merchandise Found")); } return(Ok(books[0])); }
public ActionResult Checkout(string id, bool?error) { if (error != null) { if (error == true) { ViewBag.Message = "The borrower already has checked out 3 book. Cannot checkout any more books!"; } } Repo.UtilityFunctions uf = new Repo.UtilityFunctions(); BookSearch book = uf.BookSearch(id).First(); return(View(book)); }
public void TestSearchAllFieldsForISBN() { //Arrange PersonBLLCollection people = CreatePersonBLLCollection(); BookBLLCollection books = CreateBookCollection(); string query = "3003"; //Act BookSearch search = new BookSearch(books, people, query); search.SearchAllFields(); //Assert Assert.AreEqual(1, search.FoundBooks.Count); }
public void TestSearchForOnlyISBN() { //Arrange PersonBLLCollection people = CreatePersonBLLCollection(); BookBLLCollection books = CreateBookCollection(); string query = "4004"; //Act BookSearch search = new BookSearch(books, people, query); search.ISBNSearch(); //Assert Assert.AreEqual(1, search.FoundBooks.Count); }
public void TestSearchForWordNotThere() { //Arrange PersonBLLCollection people = CreatePersonBLLCollection(); BookBLLCollection books = CreateBookCollection(); string query = "Zebra"; //Act BookSearch search = new BookSearch(books, people, query); search.SearchAllFields(); //Assert Assert.AreEqual(0, search.FoundBooks.Count); }
private void CreateDataAPI() { _search = new BookSearch(); _searchParams = new BookSearchParameters(); _search.AccessKeyId = "xx"; _search.AssociateTag = "xx"; _searchParams.Keywords = SearchTerm; _searchParams.MaxResults = Count; }