Exemplo n.º 1
0
        private void ImportEncounters()
        {
            foreach (byte[] encounterBytes in _encounters)
            {
                EncounterModel encounterModel = _dataManager.GetEncounter(encounterBytes, _compendium.Characters, _compendium.Conditions, _compendium.Monsters);

                if (_addAllEntries)
                {
                    _compendium.AddEncounter(encounterModel);
                }
                else if (_skipDuplicateEntries)
                {
                    if (!_compendium.Encounters.Any(x => x.Name.Equals(encounterModel.Name, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        _compendium.AddEncounter(encounterModel);
                    }
                }
                else if (_replaceExistingEntries)
                {
                    EncounterModel existing = _compendium.Encounters.FirstOrDefault(x => x.Name.Equals(encounterModel.Name, StringComparison.CurrentCultureIgnoreCase));
                    if (existing == null)
                    {
                        _compendium.AddEncounter(encounterModel);
                    }
                    else
                    {
                        encounterModel.Id = existing.Id;
                        _compendium.UpdateEncounter(encounterModel);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Add()
        {
            bool addEncounter = true;

            if (_encounterEditViewModel != null)
            {
                if (_editHasUnsavedChanges)
                {
                    string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                _selectedEncounter.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 (!SaveEditEncounter())
                        {
                            addEncounter = false;
                        }
                    }
                    else if (result == false)
                    {
                        CancelEditEncounter();
                    }
                    else
                    {
                        addEncounter = false;
                    }
                }
                else
                {
                    CancelEditEncounter();
                }
            }

            if (addEncounter)
            {
                EncounterModel encounterModel = new EncounterModel();
                encounterModel.Name = "New Encounter";

                _compendium.AddEncounter(encounterModel);

                if (_encounterSearchService.SearchInputApplies(_encounterSearchInput, encounterModel))
                {
                    EncounterListItemViewModel listItem = new EncounterListItemViewModel(encounterModel);
                    _encounters.Add(listItem);
                    foreach (EncounterListItemViewModel item in _encounters)
                    {
                        item.IsSelected = false;
                    }
                    listItem.IsSelected = true;
                }

                _selectedEncounter = new EncounterViewModel(encounterModel);

                _encounterEditViewModel = new EncounterViewModel(encounterModel);
                _encounterEditViewModel.PropertyChanged += _encounterEditViewModel_PropertyChanged;

                SortEncounters();

                _compendium.SaveEncounters();

                OnPropertyChanged(nameof(EditingEncounter));
                OnPropertyChanged(nameof(IsEditingEncounter));
                OnPropertyChanged(nameof(SelectedEncounter));
            }
        }