public void VerifyWhenGenreIsSetThatItSearchesWithGenreToo() { var booksService = new Mock <IBooksService>(); BookFilter filter = null; booksService.Setup(s => s.GetItems(It.IsAny <BookFilter>())) .Returns(async(BookFilter f) => { filter = f; return(new PaginatedEnumerable <BookDto>(new[] { new BookDto(), new BookDto(), new BookDto() }, 3)); }); var delayService = new Mock <IDelayService>(); delayService.Setup(service => service.Delay(It.IsAny <int>())).Returns(async() => { }); var viewModel = new SearchViewModel(booksService.Object, delayService.Object); var genre = new GenreDto { Id = 42 }; viewModel.Genre = genre; viewModel.SearchText = "Fisk"; filter.ShouldNotBeNull(); booksService.Verify(service => service.GetItems(filter), Times.Once); filter.Genres.Length.ShouldBe(1); filter.Genres[0].ShouldBe(42); }
public void Start() { BookManager manager = new BookManager(); BookFilter isNovel = BookFilters.IsNovel; BookFilter isRomance = BookFilters.IsRomance; BookFilter isShortStory = BookFilters.IsShortStory; BookFilter isFantasy = BookFilters.IsFantasy; BookFilter isMyster = BookFilters.IsMystery; BookFilter isCheap = BookFilters.IsCheap; BookFilter isExpensive = BookFilters.IsExpensive; Console.WriteLine("Novels: "); manager.PrintWhere(isNovel); Console.WriteLine("\nRomance: "); manager.PrintWhere(isRomance); Console.WriteLine("\nShorty Story: "); manager.PrintWhere(isShortStory); Console.WriteLine("\nFantasy: "); manager.PrintWhere(isFantasy); Console.WriteLine("\nMystery: "); manager.PrintWhere(isMyster); Console.WriteLine("\nCheap books that costs less than 100 SEK: "); manager.PrintWhere(isCheap); Console.WriteLine("\nExpensive books that costs more than 100 SEK: "); manager.PrintWhere(isExpensive); }
public List <Book> GetByFilter(BookFilter filter) { var query = _context.Books.AsQueryable(); if (filter.Id != null) { query = query.Where(x => x.Id == filter.Id); } if (filter.Code != null && filter.Code > 0) { query = query.Where(x => x.Code == filter.Code); } if (!string.IsNullOrEmpty(filter.Name)) { query = query.Where(x => x.Name.Contains(filter.Name)); } if (!string.IsNullOrEmpty(filter.Author)) { query = query.Where(x => x.Author.Contains(filter.Author)); } if (!string.IsNullOrEmpty(filter.Isbn)) { query = query.Where(x => x.Isbn.Contains(filter.Isbn)); } if (filter.ReleaseYear != null && filter.ReleaseYear > 0) { query = query.Where(x => x.ReleaseYear == filter.ReleaseYear); } return(query.OrderBy(x => x.Name).ToList()); }
public LibraryDTO FilterBooks(BookFilter bookFilter) { try { LibraryDTO libraryDto = null; if (bookFilter != null && (!string.IsNullOrWhiteSpace(bookFilter.ISBN) || (!string.IsNullOrWhiteSpace(bookFilter.AuthorName) && !string.IsNullOrWhiteSpace(bookFilter.Title)))) { libraryDto = _bookRepository.FilterBooks(bookFilter); if (libraryDto == null || libraryDto.Books == null || libraryDto.Books.Count() < 1) { libraryDto = GetBooksFromLibraryExpress(_urlHttpClient, _bookRepository, bookFilter); } } else { libraryDto = GetBooksFromLibraryExpress(_urlHttpClient, _bookRepository, bookFilter); } return(libraryDto); } catch (Exception ex) { //TODO: Log this the exception information along with the method details to the database for Error tracing //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point return(null); } }
public IDbCommand FilterBooks(BookFilter bookFilter, IDbCommand command) { try { command.CommandText = @"exec [dbo].[GetBooks] @ISBN,@Title,@Author";//,@Offset,@Limit"; var parameter = command.CreateParameter(); parameter.ParameterName = "@ISBN"; parameter.Value = bookFilter.ISBN == null ? string.Empty : bookFilter.ISBN; command.Parameters.Add(parameter); parameter = command.CreateParameter(); parameter.ParameterName = "@Title"; parameter.Value = bookFilter.Title == null ? string.Empty : bookFilter.Title; command.Parameters.Add(parameter); parameter = command.CreateParameter(); parameter.ParameterName = "@Author"; parameter.Value = bookFilter.AuthorName == null ? string.Empty : bookFilter.AuthorName; command.Parameters.Add(parameter); return(command); } catch (Exception ex) { //TODO: Log this the exception information along with the method details to the database for Error tracing //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point return(null); } }
public void DeleteBookById(int id) { BookFilter request = new BookFilter { BookID = id }; var deletedBook = bookClient.Delete(request); }
private void ClearFilter_OnMouseLeftButtonUp(object sender, RoutedEventArgs routedEventArgs) { Filter = new BookFilter(); FilterName.Text = String.Empty; FilterName.Visibility = Visibility.Collapsed; BookGridReload(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Go to the previous footnote in the footnote view /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ public override ScrFootnote GoToPreviousFootnote() { CheckDisposed(); // In case no footnote is selected - can happen when footnote pane is first opened. if (CurrentSelection == null) { return(null); } // Get the information needed from the current selection int iBook = CurrentSelection.GetLevelInfoForTag(BookFilter.Tag).ihvo; int iFootnote = CurrentSelection.GetLevelInfoForTag((int)ScrBook.ScrBookTags.kflidFootnotes).ihvo; ScrBook book = BookFilter.GetBook(iBook); // Get the previous footnote if it exists if (--iFootnote < 0) { return(null); } ScrFootnote footnote = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[iFootnote]); ScrollToFootnote(iBook, iFootnote, 0); return(footnote); }
public async Task <IHttpActionResult> MyBooks([FromUri] BookFilter filter = null) { filter = filter ?? new BookFilter(); var person = await this.GetAuthorizedMember(this._authRepository); return(await this.Try(() => this._bookRepository.GetByFilter(filter, person.PersonDto.Id))); }
public IActionResult Get(BookFilter filter) { if (filter == null) { //logger. } return(Ok(searchManager.GetBooks(filter))); }
public override Task <Empty> Delete(BookFilter requestData, ServerCallContext context) { var data = db.Books.Find(requestData.BookID); db.Books.Remove(data); db.SaveChanges(); return(Task.FromResult(new Empty())); }
public override BookContainer <SpecialLiterature> Search(string text, BookFilter filter, string type = null, BookContainer <SpecialLiterature> section = null, int?sectionId = null) { SpecialLiteratureSection books = new SpecialLiteratureSection(); base.Search(text, filter, "SpecialLiterature", books, 2); return(GetSpecialLiterature(books, type, section, sectionId)); }
public IList <BookItem> GetFilteredBooks(BookFilter filter) { var books = Context.Books.GetFilteredBooks(filter); var bookItems = books.Select(w => Mapper.BookMapper.MapToItem(w)).ToList(); return(bookItems); }
public override BookContainer <Schoolbook> Search(string text, BookFilter filter, string type = null, BookContainer <Schoolbook> section = null, int?sectionId = null) { SchoolbookSection books = new SchoolbookSection(); base.Search(text, filter, "Schoolbook", books, 3); return(GetSchoolbooks(books, type, section, sectionId)); }
public BookFilter(BookFilter filter) { this.Title = filter.Title; this.Author = filter.Author; this.AdditionalInfo = filter.AdditionalInfo; this.ISBN = filter.ISBN; this.RootCategoryId = filter.RootCategoryId; }
/// <summary> /// Gets the items, using the provided Filter. /// </summary> /// <param name="filter">The filter.</param> /// <returns></returns> public async Task <IPaginatedEnumerable <BookDto> > GetItems(BookFilter filter) { if (!filter.MyBooks) { return(await this.booksApi.GetBooks(filter)); } return(await this.booksApi.GetMyBooks(filter)); }
public override BookContainer <Detective> Search(string text, BookFilter filter, string type = null, BookContainer <Detective> section = null, int?sectionId = null) { DetectiveSection books = new DetectiveSection(); base.Search(text, filter, "Detective", books, 1); return(GetDetectives(books, type, section, sectionId)); }
// GET: Book public ActionResult GetBooks(BookFilter filter) { var data = _bookService.GetByFilter(1, filter); return(new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public void PrintWhere(BookFilter filter) { foreach (Book book in Books) { if (filter(book)) { Console.WriteLine(book.Title); } } }
public void Test(List <Book> books) { var filter = new BookFilter(); filter.Page = 1; filter.PerPage = 2; filter.Year = new Types.Range <int>(min: 1990, max: 2021); books.AsQueryable().ApplyFilter(filter); }
public void PrintWhere(BookFilter bookFilter) { foreach (var book in bookList) { if (bookFilter(book)) { Console.WriteLine(book); } } }
public IList <BookEntity> GetFilteredBooks(BookFilter filter) { var query = GetFiltered(DbSet.AsQueryable(), filter); return(query .Include(w => w.Author) .Include(w => w.LastUser) .Include(w => w.Publisher) .ToList()); }
public List <Book> FilteredBooks(BookFilter filter) { try { return(_repository.GetByFilter(filter)); } catch (Exception e) { throw e; } }
public async Task <List <Book> > GetFreeBooks() { try { var entityList = _bookRepository.GetAll(); var books = BookFilter.FilterFreeBooks(entityList); return(books.ToList()); } catch { return(null); } }
public BookGrid(ConnectionSettings connectionSettings, bool fromOtherView = false) { this.fromOtherView = fromOtherView; _connectionSettings = Guard.GetNotNull(connectionSettings, "connectionSettings"); InitializeComponent(); Filter = new BookFilter(connectionSettings); DataContext = Filter; CountPages(); InitTable(); SetFiltersToNull(); Filter_Click(null, null); }
public BookVM GetBookById(int id, string token) { var headers = new Metadata(); headers.Add("Authorization", $"Bearer {token}"); BookFilter request = new BookFilter { BookID = id }; var book = bookClient.SelectByID(request, headers); return(book); }
private IQueryable <BookEntity> GetFiltered(IQueryable <BookEntity> query, BookFilter filter) { if (!string.IsNullOrEmpty(filter.Name)) { var expression = GetLikeExpression(filter.Name); query = query.Where(w => EF.Functions.Like(w.Name, expression)); } if (!string.IsNullOrEmpty(filter.RegNumber)) { query = query.Where(r => filter.RegNumber == r.RegNumber); } if (filter.NumberOfPages != null) { query = query.Where(r => r.NumberOfPages == filter.NumberOfPages); } if (filter.PublicationYear != null) { query = query.Where(w => w.PublicationYear == filter.PublicationYear); } if (filter.IsBookInLibrary != null) { query = query.Where(w => w.IsBookInLibrary == filter.IsBookInLibrary); } if (!string.IsNullOrEmpty(filter.PublisherName)) { var expression = GetLikeExpression(filter.PublisherName); query = query.Where(w => EF.Functions.Like(w.Publisher.Name, expression)); } if (!string.IsNullOrEmpty(filter.AuthorName)) { var expression = GetLikeExpression(filter.AuthorName); query = query.Where(w => EF.Functions.Like(w.Author.Surname, expression) || EF.Functions.Like(w.Author.Name, expression) || EF.Functions.Like(w.Author.Patronymic, expression)); } if (!string.IsNullOrEmpty(filter.LastUserName)) { var expression = GetLikeExpression(filter.LastUserName); query = query.Where(w => EF.Functions.Like(w.LastUser.Login, expression)); } return(query); }
public HttpResponseMessage Get([FromUri] BookFilter bookFilter) { try { var expressLibraryResponse = _bookService.FindBooks(bookFilter); return(expressLibraryResponse != null?Request.CreateResponse(HttpStatusCode.OK, expressLibraryResponse) : Request.CreateResponse(HttpStatusCode.NoContent)); } catch (Exception ex) { //LOG this error return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Service is currently unavailable")); } }
public async Task <IActionResult> GetBooks(int libraryId, string query, int pageNumber = 1, int pageSize = 10, [FromQuery] int?authorId = null, [FromQuery] int?categoryId = null, [FromQuery] int?seriesId = null, [FromQuery] bool?favorite = null, [FromQuery] bool?read = null, [FromQuery] BookStatuses status = BookStatuses.Published, [FromQuery] BookSortByType sortBy = BookSortByType.Title, [FromQuery] SortDirection sortDirection = SortDirection.Ascending, CancellationToken token = default(CancellationToken)) { var filter = new BookFilter { AuthorId = authorId, CategoryId = categoryId, SeriesId = seriesId, Favorite = favorite, Read = read, Status = status }; var request = new GetBooksQuery(libraryId, pageNumber, pageSize, _userHelper.Account?.Id) { Query = query, Filter = filter, SortBy = sortBy, SortDirection = sortDirection }; var books = await _queryProcessor.ExecuteAsync(request, cancellationToken : token); var args = new PageRendererArgs <BookModel, BookFilter> { Page = books, RouteArguments = new PagedRouteArgs { PageNumber = pageNumber, PageSize = pageSize, Query = query, SortBy = sortBy, SortDirection = sortDirection }, Filters = filter, }; return(new OkObjectResult(_bookRenderer.Render(args, libraryId))); }
public ActionResult <IEnumerable <Book> > GetByFilter(BookFilter filter) { List <Book> list; try { list = _service.FilteredBooks(filter); } catch (Exception e) { return(StatusCode(404, e.Message)); } return(Ok(list)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes footnotes when there is a range selection. /// </summary> /// <param name="helper"></param> /// ------------------------------------------------------------------------------------ private void DeleteFootnoteRange(SelectionHelper helper) { int nTopLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top); int nBottomLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Bottom); // Get the index of the book containing the first footnote in the selection. // Then get the index of the footnote within that book. int iFirstBook = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 1].ihvo; int iFirstFootnote = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 2].ihvo; // Get the index of the book containing the last footnote in the selection. // Then get the index of the footnote within that book. int iLastBook = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 1].ihvo; int iLastFootnote = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 2].ihvo; // Loop through the books containing footnotes in the selection. for (int iBook = iFirstBook; iBook <= iLastBook; iBook++) { IScrBook book = BookFilter.GetBook(iBook); int iBeg = iFirstFootnote; if (iFirstBook != iLastBook && iBook > iFirstBook) { iBeg = 0; } int iEnd = iLastFootnote; if (iFirstBook != iLastBook && iBook < iLastBook) { iEnd = book.FootnotesOS.Count - 1; } // Loop through the footnotes from the selection that are in the // current book. Go in reverse order through the collection. for (int i = iEnd; i >= iBeg; i--) { // TODO: check filter for each HVO IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(book.FootnotesOS[i].Hvo); book.FootnotesOS.Remove(footnote); } } }
private void RefreshBooksList(BookFilter filter) { uxBooksList.ItemsSource = BooksManager.BooksManager.GetBooksList(filter); }
public static IList<Book> GetBooksList(BookFilter filter, SQLiteConnection connection) { List<Book> list = new List<Book>(); using (SQLiteCommand mycommand = new SQLiteCommand(connection)) { mycommand.CommandText = @"SELECT c.name as CategoryName, b.id as Id, b.category_id as CategoryId, b.title as Title, b.author as Author, b.isbn as isbn, b.additionalInfoLine1 as additionalInfoLine1,b.additionalInfoLine2 as additionalInfoLine2, b.entryDate as entryDate, b.photo as cover from book b Left outer join category c on c.id=b.category_id where b.category_id=@category_id"; if (filter.HasTextFilter) { mycommand.CommandText += " and ("; List<string> search_list = new List<string>(); if (!String.IsNullOrWhiteSpace(filter.Author)) search_list.Add(" upper(b.author) like upper(@author)"); if (!String.IsNullOrWhiteSpace(filter.Title)) search_list.Add(" upper(b.title) like upper(@title) "); if (!String.IsNullOrWhiteSpace(filter.AdditionalInfo)) search_list.Add(" upper(b.additionalInfoLine1) like upper(@additionalInfo) "); if (!String.IsNullOrWhiteSpace(filter.AdditionalInfo)) search_list.Add(" upper(b.additionalInfoLine2) like upper(@additionalInfo) "); if (!String.IsNullOrWhiteSpace(filter.ISBN)) search_list.Add(" upper(b.isbn) like upper(@isbn) "); mycommand.CommandText += string.Join("or", search_list) + ")"; } mycommand.Parameters.AddWithValue("@category_id", filter.RootCategoryId); if (!String.IsNullOrWhiteSpace(filter.Author)) mycommand.Parameters.AddWithValue("@author", "%" + filter.Author + "%"); if (!String.IsNullOrWhiteSpace(filter.Title)) mycommand.Parameters.AddWithValue("@title", "%" + filter.Title + "%"); if (!String.IsNullOrWhiteSpace(filter.AdditionalInfo)) mycommand.Parameters.AddWithValue("@additionalInfo", "%" + filter.AdditionalInfo + "%"); if (!String.IsNullOrWhiteSpace(filter.ISBN)) mycommand.Parameters.AddWithValue("@isbn", "%" + filter.ISBN + "%"); IDataReader reader = mycommand.ExecuteReader(); DataTable table = new DataTable(); table.Load(reader); if (table.Rows.Count > 0) { list.AddRange(from DataRow row in table.Rows select CreateBookRecord(row)); } reader.Close(); } foreach (Category subCategory in GetSubCategories(filter.RootCategoryId, connection).ToList()) { BookFilter newFilter = new BookFilter(filter) { RootCategoryId = subCategory.Id }; list.AddRange(GetBooksList(newFilter, connection)); } return list; }
public static IList<Book> GetBooksList(BookFilter filter) { SQLiteConnection connection = new SQLiteConnection(String.Format(connectionString, Config.DatabaseName)); connection.Open(); IList<Book> list = GetBooksList(filter, connection); connection.Close(); return list; }
public static IList<Book> GetBooksList(long selectedCategoryId) { SQLiteConnection connection = new SQLiteConnection(String.Format(connectionString, Config.DatabaseName)); connection.Open(); BookFilter filter = new BookFilter { RootCategoryId = selectedCategoryId }; IList<Book> list = GetBooksList(filter, connection); connection.Close(); return list; }