private void ImportClasses()
 {
     foreach (ClassModel classModel in _classes)
     {
         if (_addAllEntries)
         {
             _compendium.AddClass(classModel);
         }
         else if (_skipDuplicateEntries)
         {
             if (!_compendium.Classes.Any(x => x.Name.Equals(classModel.Name, StringComparison.CurrentCultureIgnoreCase)))
             {
                 _compendium.AddClass(classModel);
             }
         }
         else if (_replaceExistingEntries)
         {
             ClassModel existing = _compendium.Classes.FirstOrDefault(x => x.Name.Equals(classModel.Name, StringComparison.CurrentCultureIgnoreCase));
             if (existing == null)
             {
                 _compendium.AddClass(classModel);
             }
             else
             {
                 classModel.Id = existing.Id;
                 _compendium.UpdateClass(classModel);
             }
         }
     }
 }
Beispiel #2
0
        private void Add()
        {
            bool addClass = true;

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

            if (addClass)
            {
                string xml = "<name>New Class</name><hd>0</hd><proficiency></proficiency><spellAbility></spellAbility><autolevel level=\"1\"><feature optional=\"YES\"><name>Starting</name><text></text></feature></autolevel>";

                ClassModel classModel = _xmlImporter.GetClass(xml);

                _compendium.AddClass(classModel);

                if (_classSearchService.SearchInputApplies(_classSearchInput, classModel))
                {
                    ClassListItemViewModel listItem = new ClassListItemViewModel(classModel, _stringService);
                    _classes.Add(listItem);
                    foreach (ClassListItemViewModel item in _classes)
                    {
                        item.IsSelected = false;
                    }
                    listItem.IsSelected = true;
                }

                _selectedClass = new ClassViewModel(classModel);

                _editClassXML = classModel.XML;

                SortClasses();

                _compendium.SaveClasses();

                OnPropertyChanged(nameof(EditingClassXML));
                OnPropertyChanged(nameof(IsEditingClass));
                OnPropertyChanged(nameof(SelectedClass));
            }
        }