/// <summary> /// Returns a collection of Books sorted according to the specified sort sequence. /// </summary> /// <param name="sequence">The Sort sequence</param> /// <returns>Sorted collection of Books</returns> public static IEnumerable <BookViewModel> GetBooks(BookSortEnum sequence) { IEnumerable <BookViewModel> sortedBooks = new List <BookViewModel>(); switch (sequence) { case BookSortEnum.Title: sortedBooks = _libraryDataSource.AllBooks.OrderBy(x => x.Title); break; case BookSortEnum.Author: sortedBooks = _libraryDataSource.AllBooks.OrderBy(x => x.Author); break; } return(sortedBooks); }
/// <summary> /// Handles the Checked event for the group of radio buttons on the page /// </summary> /// <param name="sender">The RadioButton that raised the event</param> /// <param name="e">The args for the event</param> private void SelectSortSequence(object sender, RoutedEventArgs e) { // Don't process anything if the datamodel is not initialised, things are being loaded. if (this.DefaultViewModel.Count() == 0) { return; } // The button is names according to the enumeration. BookSortEnum seq = (BookSortEnum)Enum.Parse(typeof(BookSortEnum), (sender as RadioButton).Name); // Set the current sort sequence LibraryDataSource.SetSortSequence(seq); // retrieve the books sorted accordingly var books = LibraryDataSource.GetBooks(); this.DefaultViewModel["Items"] = books; }
/// <summary> /// Method <c>LoadData</c> is called to load the view model with the data /// from the underlying Data Model, via the repositories, which access /// the underlying Data Model. /// </summary> private void LoadData() { // Load _allBooks (LibraryRepository) var allBooks = _libraryRepository.GetAllBooks(); // Process each indiviually to ensure the UI observable stuff is updated. foreach (var book in allBooks) { this.AllBooks.Add(MapLibraryBookToBookViewModel.Map(book)); } // Load _allSearches (SearchRepository) var allSearches = _searchRepository.GetSearches(); foreach (var search in allSearches) { this.AllSearches.Add(MapSearchCriteriaToSearchViewModel.Map(search)); } var searchTypes = _searchRepository.GetSearchTypes(); foreach (var searchType in searchTypes) { // Create a SearchTypeViewModel SearchTypesViewModel typeVM = new SearchTypesViewModel() { Type = searchType, Values = new ObservableCollection<string>() }; // Add a "Select" message as the first value for the search Type. // TODO: Correct the Grammer for this function, select An Author, Select a Keyword. if (searchType == "SearchString") typeVM.Values.Add(string.Format("Type a value into the search string")); else typeVM.Values.Add(string.Format("Select a {0}....", searchType)); // Get the possible values from the library. var values = _libraryRepository.GetSearchableBookValues(searchType); // Add each possible value into the SearchTypesViewModel foreach (var val in values) { typeVM.Values.Add(val); } // Add the SearchType to the view model this.CurrentSearch.SearchTypes.Add(typeVM); this.SearchTypes.Add(typeVM); } // Load _currentSearch (item 0 of the searches loaded, if there are any) if (this.AllSearches.Count() == 0) { // set to new search this.CurrentSearch.UniqueId = string.Empty; this.CurrentSearch.Type = _searchTypes[0].Type; this.CurrentSearch.SearchString = string.Empty; this.CurrentSearch.SearchDate = DateTime.Now.ToString(); this.CurrentSearch.SelectedTypeIndex = 0; this.CurrentSearch.SelectedTypeValueIndex = 0; } else { // Set to the first search. this.CurrentSearch.UniqueId = this.AllSearches[0].UniqueId; this.CurrentSearch.Type = this.AllSearches[0].Type; this.CurrentSearch.SearchString = this.AllSearches[0].SearchString; this.CurrentSearch.SearchDate = this.AllSearches[0].SearchDate; int idx = this.SearchTypes.IndexOf(new SearchTypesViewModel() { Type = this.CurrentSearch.Type }); this.CurrentSearch.SelectedTypeIndex = idx; this.CurrentSearch.SelectedTypeValueIndex = 0; } // Set the default sort sequence for display, which is by Title this._currentSortSequence = BookSortEnum.Title; }
/// <summary> /// Sets the current sort sequence for displaying the list of books, as specified /// by the <see cref="THLibrary.DataModel.BookSortEnum"/> enumeration. /// </summary> /// <param name="sequence">The Sort Sequence to be set.</param> public static void SetSortSequence(BookSortEnum sequence) { _libraryDataSource._currentSortSequence = sequence; }
/// <summary> /// Returns a collection of Books sorted according to the specified sort sequence. /// </summary> /// <param name="sequence">The Sort sequence</param> /// <returns>Sorted collection of Books</returns> public static IEnumerable<BookViewModel> GetBooks(BookSortEnum sequence) { IEnumerable<BookViewModel> sortedBooks = new List<BookViewModel>(); switch (sequence) { case BookSortEnum.Title: sortedBooks = _libraryDataSource.AllBooks.OrderBy(x => x.Title); break; case BookSortEnum.Author: sortedBooks = _libraryDataSource.AllBooks.OrderBy(x => x.Author); break; } return sortedBooks; }
/// <summary> /// Method <c>LoadData</c> is called to load the view model with the data /// from the underlying Data Model, via the repositories, which access /// the underlying Data Model. /// </summary> private void LoadData() { // Load _allBooks (LibraryRepository) var allBooks = _libraryRepository.GetAllBooks(); // Process each indiviually to ensure the UI observable stuff is updated. foreach (var book in allBooks) { this.AllBooks.Add(MapLibraryBookToBookViewModel.Map(book)); } // Load _allSearches (SearchRepository) var allSearches = _searchRepository.GetSearches(); foreach (var search in allSearches) { this.AllSearches.Add(MapSearchCriteriaToSearchViewModel.Map(search)); } var searchTypes = _searchRepository.GetSearchTypes(); foreach (var searchType in searchTypes) { // Create a SearchTypeViewModel SearchTypesViewModel typeVM = new SearchTypesViewModel() { Type = searchType, Values = new ObservableCollection <string>() }; // Add a "Select" message as the first value for the search Type. // TODO: Correct the Grammer for this function, select An Author, Select a Keyword. if (searchType == "SearchString") { typeVM.Values.Add(string.Format("Type a value into the search string")); } else { typeVM.Values.Add(string.Format("Select a {0}....", searchType)); } // Get the possible values from the library. var values = _libraryRepository.GetSearchableBookValues(searchType); // Add each possible value into the SearchTypesViewModel foreach (var val in values) { typeVM.Values.Add(val); } // Add the SearchType to the view model this.CurrentSearch.SearchTypes.Add(typeVM); this.SearchTypes.Add(typeVM); } // Load _currentSearch (item 0 of the searches loaded, if there are any) if (this.AllSearches.Count() == 0) { // set to new search this.CurrentSearch.UniqueId = string.Empty; this.CurrentSearch.Type = _searchTypes[0].Type; this.CurrentSearch.SearchString = string.Empty; this.CurrentSearch.SearchDate = DateTime.Now.ToString(); this.CurrentSearch.SelectedTypeIndex = 0; this.CurrentSearch.SelectedTypeValueIndex = 0; } else { // Set to the first search. this.CurrentSearch.UniqueId = this.AllSearches[0].UniqueId; this.CurrentSearch.Type = this.AllSearches[0].Type; this.CurrentSearch.SearchString = this.AllSearches[0].SearchString; this.CurrentSearch.SearchDate = this.AllSearches[0].SearchDate; int idx = this.SearchTypes.IndexOf(new SearchTypesViewModel() { Type = this.CurrentSearch.Type }); this.CurrentSearch.SelectedTypeIndex = idx; this.CurrentSearch.SelectedTypeValueIndex = 0; } // Set the default sort sequence for display, which is by Title this._currentSortSequence = BookSortEnum.Title; }
/// <summary> /// Sets the current sort sequence for displaying the list of books, as specified /// by the <see cref="THLibrary.DataModel.BookSortEnum"/> enumeration. /// </summary> /// <param name="sequence">The Sort Sequence to be set.</param> public static void SetSortSequence(BookSortEnum sequence) { _libraryDataSource._currentSortSequence = sequence; }