private void ImportItems() { foreach (ItemModel itemModel in _items) { if (_addAllEntries) { _compendium.AddItem(itemModel); } else if (_skipDuplicateEntries) { if (!_compendium.Items.Any(x => x.Name.Equals(itemModel.Name, StringComparison.CurrentCultureIgnoreCase))) { _compendium.AddItem(itemModel); } } else if (_replaceExistingEntries) { ItemModel existing = _compendium.Items.FirstOrDefault(x => x.Name.Equals(itemModel.Name, StringComparison.CurrentCultureIgnoreCase)); if (existing == null) { _compendium.AddItem(itemModel); } else { itemModel.Id = existing.Id; _compendium.UpdateItem(itemModel); } } } }
private void Add() { bool addItem = true; if (_editItemXML != null) { if (_editHasUnsavedChanges) { string body = String.Format("{0} has unsaved changes.{1}What would you like to do?", _selectedItem.Name, Environment.NewLine + Environment.NewLine); string accept = "Save and Continue"; string reject = "Discard Changes"; string cancel = "Cancel Navigation"; bool? result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel); if (result == true) { if (!SaveEditItem()) { addItem = false; } } else if (result == false) { CancelEditItem(); } else { addItem = false; } } else { CancelEditItem(); } } if (addItem) { string xml = @"<name>New Item</name> <type></type> <magic></magic> <value></value> <detail></detail> <weight></weight> <ac></ac> <strength></strength> <stealth></stealth> <dmg1></dmg1> <dmg2></dmg2> <dmgType></dmgType> <property></property> <rarity></rarity> <range></range> <text></text> <modifier category=""""></modifier> <roll></roll>" ; ItemModel itemModel = _xmlImporter.GetItem(xml); _compendium.AddItem(itemModel); if (_itemSearchService.SearchInputApplies(_itemSearchInput, itemModel)) { ItemListItemViewModel listItem = new ItemListItemViewModel(itemModel, _stringService); _items.Add(listItem); foreach (ItemListItemViewModel item in _items) { item.IsSelected = false; } listItem.IsSelected = true; } _selectedItem = new ItemViewModel(itemModel); _editItemXML = itemModel.XML; SortItems(); _compendium.SaveItems(); OnPropertyChanged(nameof(EditingItemXML)); OnPropertyChanged(nameof(IsEditingItem)); OnPropertyChanged(nameof(SelectedItem)); } }