private void CancelEditNPC() { _editHasUnsavedChanges = false; _npcEditViewModel = null; OnPropertyChanged(nameof(EditingNPC)); OnPropertyChanged(nameof(IsEditingNPC)); OnPropertyChanged(nameof(HasUnsavedChanges)); }
private void EditNPC(NPCViewModel npcModel) { if (npcModel != null) { _npcEditViewModel = new NPCEditViewModel(npcModel.NPCModel); _npcEditViewModel.PropertyChanged += _npcEditViewModel_PropertyChanged; OnPropertyChanged(nameof(EditingNPC)); OnPropertyChanged(nameof(IsEditingNPC)); } }
private bool SaveEditNPC() { bool saved = false; if (_npcEditViewModel.NPCModel != null) { _npcEditViewModel.NPCModel.Id = _selectedNPC.NPCModel.Id; _compendium.UpdateNPC(_npcEditViewModel.NPCModel); _selectedNPC = new NPCViewModel(_npcEditViewModel.NPCModel); ListItemViewModel <NPCModel> oldListItem = _npcs.FirstOrDefault(x => x.Model.Id == _npcEditViewModel.NPCModel.Id); if (oldListItem != null) { if (_npcSearchService.SearchInputApplies(_npcSearchInput, _npcEditViewModel.NPCModel)) { InitializeListItemDetails(oldListItem, _npcEditViewModel.NPCModel); } else { _npcs.Remove(oldListItem); } } _npcEditViewModel = null; _editHasUnsavedChanges = false; SortNPCs(); _compendium.SaveNPCs(); OnPropertyChanged(nameof(SelectedNPC)); OnPropertyChanged(nameof(EditingNPC)); OnPropertyChanged(nameof(IsEditingNPC)); OnPropertyChanged(nameof(HasUnsavedChanges)); saved = true; } return(saved); }
private void Add() { bool addNPC = true; if (_npcEditViewModel != null) { if (_editHasUnsavedChanges) { string body = String.Format("{0} has unsaved changes.{1}What would you like to do?", _selectedNPC.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 (!SaveEditNPC()) { addNPC = false; } } else if (result == false) { CancelEditNPC(); } else { addNPC = false; } } else { CancelEditNPC(); } } if (addNPC) { NPCModel npcModel = new NPCModel(); _compendium.AddNPC(npcModel); if (_npcSearchService.SearchInputApplies(_npcSearchInput, npcModel)) { ListItemViewModel <NPCModel> listItem = new ListItemViewModel <NPCModel>(npcModel); InitializeListItemDetails(listItem, npcModel); _npcs.Add(listItem); foreach (ListItemViewModel <NPCModel> item in _npcs) { item.IsSelected = false; } listItem.IsSelected = true; } _selectedNPC = new NPCViewModel(npcModel); _npcEditViewModel = new NPCEditViewModel(npcModel); _npcEditViewModel.PropertyChanged += _npcEditViewModel_PropertyChanged; SortNPCs(); _compendium.SaveNPCs(); OnPropertyChanged(nameof(EditingNPC)); OnPropertyChanged(nameof(IsEditingNPC)); OnPropertyChanged(nameof(SelectedNPC)); } }