예제 #1
0
        private bool SaveEditRace()
        {
            bool saved = false;

            try
            {
                RaceModel model = _xmlImporter.GetRace(_editRaceXML);

                if (model != null)
                {
                    model.Id = _selectedRace.RaceModel.Id;
                    _compendium.UpdateRace(model);
                    _selectedRace = new RaceViewModel(model);

                    RaceListItemViewModel oldListItem = _races.FirstOrDefault(x => x.RaceModel.Id == model.Id);
                    if (oldListItem != null)
                    {
                        if (_raceSearchService.SearchInputApplies(_raceSearchInput, model))
                        {
                            oldListItem.UpdateModel(model);
                        }
                        else
                        {
                            _races.Remove(oldListItem);
                        }
                    }

                    _editRaceXML           = null;
                    _editHasUnsavedChanges = false;

                    SortRaces();

                    _compendium.SaveRaces();

                    OnPropertyChanged(nameof(SelectedRace));
                    OnPropertyChanged(nameof(EditingRaceXML));
                    OnPropertyChanged(nameof(IsEditingRace));
                    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);
        }