/// <summary> /// Returns a collection of Books that match the specified search criteria, and /// sorted according to the current sort sequence. /// </summary> /// <param name="criteria">The criteria use to match the bolks.</param> /// <returns>Sorted collection of matching Books.</returns> public static IEnumerable <BookViewModel> GetMatchingBooks(SearchViewModel criteria) { // Return empty list if search criteria not specified. if (criteria == null) { return(new List <BookViewModel>()); } // Clear out the existing books. _libraryDataSource.AllBooks.Clear(); // Map the search criteria. // Instantiate the mapper class. var mapper = new MapSearchViewModelToSearchCriteria <SearchViewModel>(_libraryDataSource._ioc.Resolve <SearchCriteriaFactory>()); // Map the SearchViewModel to the SearchCriteria. var searchCriteria = mapper.Map(criteria); // Call the repository, SearchBooks() var allBooks = _libraryDataSource._libraryRepository.SearchBooks(searchCriteria); foreach (var book in allBooks) { _libraryDataSource.AllBooks.Add(MapLibraryBookToBookViewModel.Map(book)); } // Call the GetBooks method as this will invoke the current sort for the results. return(GetBooks()); }
/// <summary> /// Adds the search contained in the CurrentSearchviewModel to the collection of Searches. /// </summary> /// <param name="newSearch">The CurrentSearchViewModel</param> public static void AddSearch(CurrentSearchViewModel newSearch) { // Map the SearchViewModel to the SearchCriteria. var mapper = new MapSearchViewModelToSearchCriteria <CurrentSearchViewModel>(_libraryDataSource._ioc.Resolve <SearchCriteriaFactory>()); var searchCriteria = mapper.Map(newSearch); // Save in the data model var id = _libraryDataSource._searchRepository.AddSearch(searchCriteria); // Add to the UI. _libraryDataSource.AllSearches.Add(MapSearchCriteriaToSearchViewModel.Map(searchCriteria)); }
/// <summary> /// Returns a collection of Books that match the specified search criteria, and /// sorted according to the current sort sequence. /// </summary> /// <param name="criteria">The criteria use to match the bolks.</param> /// <returns>Sorted collection of matching Books.</returns> public static IEnumerable<BookViewModel> GetMatchingBooks(SearchViewModel criteria) { // Return empty list if search criteria not specified. if (criteria == null) return new List<BookViewModel>(); // Clear out the existing books. _libraryDataSource.AllBooks.Clear(); // Map the search criteria. // Instantiate the mapper class. var mapper = new MapSearchViewModelToSearchCriteria<SearchViewModel>(_libraryDataSource._ioc.Resolve<SearchCriteriaFactory>()); // Map the SearchViewModel to the SearchCriteria. var searchCriteria = mapper.Map(criteria); // Call the repository, SearchBooks() var allBooks = _libraryDataSource._libraryRepository.SearchBooks(searchCriteria); foreach (var book in allBooks) { _libraryDataSource.AllBooks.Add(MapLibraryBookToBookViewModel.Map(book)); } // Call the GetBooks method as this will invoke the current sort for the results. return GetBooks(); }
/// <summary> /// Adds the search contained in the CurrentSearchviewModel to the collection of Searches. /// </summary> /// <param name="newSearch">The CurrentSearchViewModel</param> public static void AddSearch(CurrentSearchViewModel newSearch) { // Map the SearchViewModel to the SearchCriteria. var mapper = new MapSearchViewModelToSearchCriteria<CurrentSearchViewModel>(_libraryDataSource._ioc.Resolve<SearchCriteriaFactory>()); var searchCriteria = mapper.Map(newSearch); // Save in the data model var id = _libraryDataSource._searchRepository.AddSearch(searchCriteria); // Add to the UI. _libraryDataSource.AllSearches.Add(MapSearchCriteriaToSearchViewModel.Map(searchCriteria)); }