private void ImportCharacters() { foreach (byte[] characterBytes in _characters) { CharacterModel characterModel = _dataManager.GetCharacter(characterBytes, _compendium.Backgrounds, _compendium.Classes, _compendium.Conditions, _compendium.Feats, _compendium.Items, _compendium.Languages, _compendium.Monsters, _compendium.Races, _compendium.Spells); if (_addAllEntries) { _compendium.AddCharacter(characterModel); } else if (_skipDuplicateEntries) { if (!_compendium.Characters.Any(x => x.Name.Equals(characterModel.Name, StringComparison.CurrentCultureIgnoreCase))) { _compendium.AddCharacter(characterModel); } } else if (_replaceExistingEntries) { CharacterModel existing = _compendium.Characters.FirstOrDefault(x => x.Name.Equals(characterModel.Name, StringComparison.CurrentCultureIgnoreCase)); if (existing == null) { _compendium.AddCharacter(characterModel); } else { characterModel.Id = existing.Id; _compendium.UpdateCharacter(characterModel); } } } }
private void Add() { bool addCharacter = true; if (_characterEditViewModel != null) { if (_editHasUnsavedChanges) { string body = String.Format("{0} has unsaved changes.{1}What would you like to do?", _selectedCharacter.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 (!SaveEditCharacter()) { addCharacter = false; } } else if (result == false) { CancelEditCharacter(); } else { addCharacter = false; } } else { CancelEditCharacter(); } } if (addCharacter) { _characterEditViewModel = new CharacterEditViewModel(new CharacterModel(), true); _compendium.AddCharacter(_characterEditViewModel.CharacterModel); if (_characterSearchService.SearchInputApplies(_characterSearchInput, _characterEditViewModel.CharacterModel)) { CharacterListItemViewModel listItem = new CharacterListItemViewModel(_characterEditViewModel.CharacterModel); _characters.Add(listItem); foreach (CharacterListItemViewModel item in _characters) { item.IsSelected = false; } listItem.IsSelected = true; } _selectedCharacter = new CharacterViewModel(_characterEditViewModel.CharacterModel); _characterEditViewModel.PropertyChanged += _characterEditViewModel_PropertyChanged; SelectInfoEdit(); SortCharacters(); _compendium.SaveCharacters(); OnPropertyChanged(nameof(EditingCharacter)); OnPropertyChanged(nameof(IsEditingCharacter)); OnPropertyChanged(nameof(SelectedCharacter)); } }