Exemplo n.º 1
0
 private void ImportBackgrounds()
 {
     foreach (BackgroundModel backgroundModel in _backgrounds)
     {
         if (_addAllEntries)
         {
             _compendium.AddBackground(backgroundModel);
         }
         else if (_skipDuplicateEntries)
         {
             if (!_compendium.Backgrounds.Any(x => x.Name.Equals(backgroundModel.Name, StringComparison.CurrentCultureIgnoreCase)))
             {
                 _compendium.Backgrounds.Add(backgroundModel);
             }
         }
         else if (_replaceExistingEntries)
         {
             BackgroundModel existing = _compendium.Backgrounds.FirstOrDefault(x => x.Name.Equals(backgroundModel.Name, StringComparison.CurrentCultureIgnoreCase));
             if (existing == null)
             {
                 _compendium.AddBackground(backgroundModel);
             }
             else
             {
                 backgroundModel.Id = existing.Id;
                 _compendium.UpdateBackground(backgroundModel);
             }
         }
     }
 }
Exemplo n.º 2
0
        private void Add()
        {
            bool addBackground = true;

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

            if (addBackground)
            {
                string xml = "<name>New Background</name><proficiency></proficiency><trait><name></name><text></text></trait>";

                BackgroundModel backgroundModel = _xmlImporter.GetBackground(xml);

                _compendium.AddBackground(backgroundModel);

                if (_backgroundSearchService.SearchInputApplies(_backgroundSearchInput, backgroundModel))
                {
                    BackgroundListItemViewModel listItem = new BackgroundListItemViewModel(backgroundModel, _stringService);
                    _backgrounds.Add(listItem);
                    foreach (BackgroundListItemViewModel item in _backgrounds)
                    {
                        item.IsSelected = false;
                    }
                    listItem.IsSelected = true;
                }

                _selectedBackground = new BackgroundViewModel(backgroundModel);

                _editBackgroundXML = backgroundModel.XML;

                SortBackgrounds();

                _compendium.SaveBackgrounds();

                OnPropertyChanged(nameof(EditingBackgroundXML));
                OnPropertyChanged(nameof(IsEditingBackground));
                OnPropertyChanged(nameof(SelectedBackground));
            }
        }