Пример #1
0
        private bool SaveEditBackground()
        {
            bool saved = false;

            try
            {
                BackgroundModel model = _xmlImporter.GetBackground(_editBackgroundXML);

                if (model != null)
                {
                    model.Id = _selectedBackground.BackgroundModel.Id;
                    _compendium.UpdateBackground(model);
                    _selectedBackground = new BackgroundViewModel(model);

                    BackgroundListItemViewModel oldListItem = _backgrounds.FirstOrDefault(x => x.BackgroundModel.Id == model.Id);
                    if (oldListItem != null)
                    {
                        if (_backgroundSearchService.SearchInputApplies(_backgroundSearchInput, model))
                        {
                            oldListItem.UpdateModel(model);
                        }
                        else
                        {
                            _backgrounds.Remove(oldListItem);
                        }
                    }

                    _editBackgroundXML     = null;
                    _editHasUnsavedChanges = false;

                    SortBackgrounds();

                    _compendium.SaveBackgrounds();

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

                    saved = true;
                }
                else
                {
                    string message = String.Format("Something went wrong...{0}{1}{2}{3}",
                                                   Environment.NewLine + Environment.NewLine,
                                                   "The following are required:",
                                                   Environment.NewLine,
                                                   "-name");
                    _dialogService.ShowConfirmationDialog("Unable To Save", message, "OK", null, null);
                }
            }
            catch (Exception ex)
            {
                string message = String.Format("Something went wrong...{0}{1}",
                                               Environment.NewLine + Environment.NewLine,
                                               ex.Message);
                _dialogService.ShowConfirmationDialog("Unable To Save", message, "OK", null, null);
            }

            return(saved);
        }