/// <summary> /// Creates an instance of <see cref="ItemsViewModel"/> /// </summary> public ItemsViewModel(Compendium compendium, ItemSearchService itemSearchService, ItemSearchInput itemSearchInput, StringService stringService, DialogService dialogService, XMLImporter xmlImporter, XMLExporter xmlExporter, DocumentService documentService) { _compendium = compendium; _itemSearchService = itemSearchService; _itemSearchInput = itemSearchInput; _stringService = stringService; _dialogService = dialogService; _xmlImporter = xmlImporter; _xmlExporter = xmlExporter; _documentService = documentService; _selectItemCommand = new RelayCommand(obj => true, obj => SelectItem(obj as ItemListItemViewModel)); _editItemCommand = new RelayCommand(obj => true, obj => EditItem(obj as ItemViewModel)); _exportItemCommand = new RelayCommand(obj => true, obj => ExportItem(obj as ItemViewModel)); _cancelEditItemCommand = new RelayCommand(obj => true, obj => CancelEditItem()); _saveEditItemCommand = new RelayCommand(obj => HasUnsavedChanges, obj => SaveEditItem()); _resetFiltersCommand = new RelayCommand(obj => true, obj => InitializeSearch()); _addCommand = new RelayCommand(obj => true, obj => Add()); _copyCommand = new RelayCommand(obj => _selectedItem != null, obj => Copy()); _deleteCommand = new RelayCommand(obj => _selectedItem != 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(ItemSearchInput searchInput, ItemModel itemModel) { return(HasSearchText(itemModel, searchInput.SearchText) && IsItemType(itemModel, searchInput.ItemType.Key) && IsMagicSelection(itemModel, searchInput.Magic.Key) && IsRarity(itemModel, searchInput.Rarity.Key) && IsAttunementSelection(itemModel, searchInput.RequresAttunement.Key)); }
/// <summary> /// Creates an instance of <see cref="ItemSearchViewModel"/> /// </summary> public ItemSearchViewModel(Compendium compendium, ItemSearchService itemSearchService, ItemSearchInput itemSearchInput, StringService stringService, DialogService dialogService) { _compendium = compendium; _itemSearchService = itemSearchService; _itemSearchInput = itemSearchInput; _stringService = stringService; _dialogService = dialogService; _selectItemCommand = new RelayCommand(obj => true, obj => SelectItem(obj as ItemListItemViewModel)); _resetFiltersCommand = new RelayCommand(obj => true, obj => InitializeSearch()); _acceptCommand = new RelayCommand(obj => true, obj => OnAccept()); _rejectCommand = new RelayCommand(obj => true, obj => OnReject()); Search(); }
/// <summary> /// Searches the compendium for items matching the search input /// </summary> public List <ItemModel> Search(ItemSearchInput searchInput) { return(Sort(_compendium.Items.Where(x => SearchInputApplies(searchInput, x)), searchInput.SortOption.Key)); }