/// <summary> /// Creates an instance of <see cref="AdventuresViewModel"/> /// </summary> public AdventuresViewModel(Compendium compendium, AdventureSearchService adventureSearchService, AdventureSearchInput adventureSearchInput, StringService stringService, DialogService dialogService, XMLImporter xmlImporter, DocumentService documentService, DataManager dataManager) { _compendium = compendium; _adventureSearchService = adventureSearchService; _adventureSearchInput = adventureSearchInput; _stringService = stringService; _dialogService = dialogService; _xmlImporter = xmlImporter; _documentService = documentService; _dataManager = dataManager; _selectAdventureCommand = new RelayCommand(obj => true, obj => SelectAdventure(obj as ListItemViewModel <AdventureModel>)); _editAdventureCommand = new RelayCommand(obj => true, obj => EditAdventure(obj as AdventureViewModel)); _exportAdventureCommand = new RelayCommand(obj => true, obj => ExportAdventure(obj as AdventureViewModel)); _cancelEditAdventureCommand = new RelayCommand(obj => true, obj => CancelEditAdventure()); _saveEditAdventureCommand = new RelayCommand(obj => HasUnsavedChanges, obj => SaveEditAdventure()); _resetFiltersCommand = new RelayCommand(obj => true, obj => InitializeSearch()); _addCommand = new RelayCommand(obj => true, obj => Add()); _copyCommand = new RelayCommand(obj => _selectedAdventure != null, obj => Copy()); _deleteCommand = new RelayCommand(obj => _selectedAdventure != null, obj => Delete()); _importCommand = new RelayCommand(obj => true, obj => Import()); _selectNextCommand = new RelayCommand(obj => true, obj => SelectNext()); _selectPreviousCommand = new RelayCommand(obj => true, obj => SelectPrevious()); Search(); }
/// <summary> /// True if the search input applies to the model /// </summary> public bool SearchInputApplies(AdventureSearchInput searchInput, AdventureModel adventureModel) { return(HasSearchText(adventureModel, searchInput.SearchText) && HasTag(adventureModel, searchInput.Tag.Key)); }
/// <summary> /// Searches the compendium for adventures matching the search input /// </summary> public List <AdventureModel> Search(AdventureSearchInput searchInput) { return(Sort(_compendium.Adventures.Where(x => SearchInputApplies(searchInput, x)), searchInput.SortOption.Key)); }