Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        /// <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;
        }