private void ExportFeat(FeatViewModel featViewModel)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter   = "XML Document|*.xml";
            saveFileDialog.Title    = "Save Feat";
            saveFileDialog.FileName = featViewModel.Name;

            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    string ext = System.IO.Path.GetExtension(saveFileDialog.FileName);

                    if (ext == ".xml")
                    {
                        string xml = _xmlExporter.FormatXMLWithHeader(_xmlExporter.GetXML(featViewModel.FeatModel));
                        System.IO.File.WriteAllText(saveFileDialog.FileName, xml, System.Text.Encoding.UTF8);
                    }
                    else
                    {
                        _dialogService.ShowConfirmationDialog("Unable To Export", "Invalid file extension.", "OK", null, null);
                    }
                }
                catch (Exception)
                {
                    _dialogService.ShowConfirmationDialog("Unable To Export", "An error occurred when attempting to export the feat.", "OK", null, null);
                }
            }
        }
        private void SelectPrevious()
        {
            if (_feats.Any())
            {
                FeatListItemViewModel selected = _feats.FirstOrDefault(x => x.IsSelected);

                foreach (FeatListItemViewModel feat in _feats)
                {
                    feat.IsSelected = false;
                }

                if (selected == null)
                {
                    _feats[_feats.Count - 1].IsSelected = true;
                    _selectedFeat = new FeatViewModel(_feats[_feats.Count - 1].FeatModel);
                }
                else
                {
                    int index = Math.Max(_feats.IndexOf(selected) - 1, 0);
                    _feats[index].IsSelected = true;
                    _selectedFeat            = new FeatViewModel(_feats[index].FeatModel);
                }

                OnPropertyChanged(nameof(SelectedFeat));
            }
        }
        private void EditFeat(FeatViewModel featModel)
        {
            _editFeatXML = featModel.XML;

            OnPropertyChanged(nameof(EditingFeatXML));
            OnPropertyChanged(nameof(IsEditingFeat));
        }
示例#4
0
        public FeatViewModel AddFeat(FeatViewModel feat)
        {
            var featToAdd = FeatMapper.MapModelToEntity(feat);

            featToAdd.CreatedBy = "TEST";
            featToAdd.SeedData  = false;
            var addedFeat = _featRepository.Add(featToAdd);

            return(FeatMapper.MapEntityToModel(addedFeat));
        }
示例#5
0
        public FeatViewModel PutFeat(int id, FeatViewModel feat)
        {
            var featToUpdate = _featRepository.GetById(id);

            FeatMapper.MapModelToEntity(feat, featToUpdate);
            featToUpdate.ModifiedBy = "TEST";
            var updatedFeat = _featRepository.Update(featToUpdate);

            return(FeatMapper.MapEntityToModel(updatedFeat));
        }
示例#6
0
        /// <summary>
        /// Shows details dialog
        /// </summary>
        public void ShowDetailsDialog(FeatViewModel featViewModel)
        {
            ModalDialog modalDialog = new ModalDialog();

            if (_parentWindow != null)
            {
                modalDialog.Owner = _parentWindow;
            }

            modalDialog.WindowTitle = featViewModel.Name;
            modalDialog.Body        = new DetailsView(featViewModel);

            ShowDialog(modalDialog);
        }
        private void SelectFeat(FeatListItemViewModel featItem)
        {
            bool selectFeat = true;

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

            if (selectFeat)
            {
                foreach (FeatListItemViewModel item in _feats)
                {
                    item.IsSelected = false;
                }
                featItem.IsSelected = true;

                _selectedFeat = new FeatViewModel(featItem.FeatModel);
                OnPropertyChanged(nameof(SelectedFeat));
            }
        }
示例#8
0
        public IActionResult GetFeatById(int id)
        {
            var viewModel = new FeatViewModel();

            try
            {
                viewModel = _miscellaneousLogicHandler.GetFeatById(id);
                _responseFormatter.Add("feat", viewModel);
                return(new OkObjectResult(_responseFormatter.GetResponse()));
            }
            catch (Exception ex)
            {
                _responseFormatter.SetError(ex.Message);
                return(new BadRequestObjectResult(_responseFormatter.GetResponse()));
            }
        }
示例#9
0
 public static void MapModelToEntity(FeatViewModel feat, Feat featEntity)
 {
     Mapper.Map(feat, featEntity);
 }
示例#10
0
 public static Feat MapModelToEntity(FeatViewModel featViewModel)
 {
     return(Mapper.Map <Feat>(featViewModel));
 }
示例#11
0
        public async Task <IHttpActionResult> Put(int id, [FromBody] FeatViewModel value)
        {
            var updatedFeat = await Task.Run(() => _featService.PutFeat(id, value));

            return(Ok(updatedFeat));
        }
示例#12
0
        private void Copy()
        {
            if (_selectedFeat != null)
            {
                bool copyFeat = true;

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

                if (copyFeat)
                {
                    FeatModel newFeat = new FeatModel(_selectedFeat.FeatModel);
                    newFeat.Name += " (copy)";
                    newFeat.Id    = Guid.NewGuid();
                    newFeat.XML   = newFeat.XML.Replace("<name>" + _selectedFeat.FeatModel.Name + "</name>",
                                                        "<name>" + newFeat.Name + "</name>");

                    _compendium.AddFeat(newFeat);

                    if (_featSearchService.SearchInputApplies(_featSearchInput, newFeat))
                    {
                        FeatListItemViewModel listItem = new FeatListItemViewModel(newFeat);
                        _feats.Add(listItem);
                        foreach (FeatListItemViewModel item in _feats)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedFeat = new FeatViewModel(newFeat);

                    SortFeats();

                    _compendium.SaveFeats();

                    OnPropertyChanged(nameof(SelectedFeat));
                }
            }
        }
示例#13
0
        private void Add()
        {
            bool addFeat = true;

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

            if (addFeat)
            {
                string xml = "<name>New Feat</name><prerequisite></prerequisite><text></text>";

                FeatModel featModel = _xmlImporter.GetFeat(xml);

                _compendium.AddFeat(featModel);

                if (_featSearchService.SearchInputApplies(_featSearchInput, featModel))
                {
                    FeatListItemViewModel listItem = new FeatListItemViewModel(featModel);
                    _feats.Add(listItem);
                    foreach (FeatListItemViewModel item in _feats)
                    {
                        item.IsSelected = false;
                    }
                    listItem.IsSelected = true;
                }

                _selectedFeat = new FeatViewModel(featModel);

                _editFeatXML = featModel.XML;

                SortFeats();

                _compendium.SaveFeats();

                OnPropertyChanged(nameof(EditingFeatXML));
                OnPropertyChanged(nameof(IsEditingFeat));
                OnPropertyChanged(nameof(SelectedFeat));
            }
        }
示例#14
0
        private bool SaveEditFeat()
        {
            bool saved = false;

            try
            {
                FeatModel model = _xmlImporter.GetFeat(_editFeatXML);

                if (model != null)
                {
                    model.Id = _selectedFeat.FeatModel.Id;
                    _compendium.UpdateFeat(model);
                    _selectedFeat = new FeatViewModel(model);

                    FeatListItemViewModel oldListItem = _feats.FirstOrDefault(x => x.FeatModel.Id == model.Id);
                    if (oldListItem != null)
                    {
                        if (_featSearchService.SearchInputApplies(_featSearchInput, model))
                        {
                            oldListItem.UpdateModel(model);
                        }
                        else
                        {
                            _feats.Remove(oldListItem);
                        }
                    }

                    _editFeatXML           = null;
                    _editHasUnsavedChanges = false;

                    SortFeats();

                    _compendium.SaveFeats();

                    OnPropertyChanged(nameof(SelectedFeat));
                    OnPropertyChanged(nameof(EditingFeatXML));
                    OnPropertyChanged(nameof(IsEditingFeat));
                    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);
        }
示例#15
0
 public FeatPage()
 {
     InitializeComponent();
     BindingContext = viewModel = new FeatViewModel();
 }
示例#16
0
        private void Delete()
        {
            if (_selectedFeat != null)
            {
                bool canDelete = true;

                foreach (CharacterModel character in _compendium.Characters)
                {
                    foreach (LevelModel level in character.Levels)
                    {
                        foreach (FeatModel feat in level.Feats)
                        {
                            if (feat.Id == _selectedFeat.FeatModel.Id)
                            {
                                canDelete = false;
                                break;
                            }
                        }

                        if (!canDelete)
                        {
                            break;
                        }
                    }

                    if (!canDelete)
                    {
                        break;
                    }
                }

                if (canDelete)
                {
                    string message = String.Format("Are you sure you want to delete {0}?",
                                                   _selectedFeat.Name);

                    bool?result = _dialogService.ShowConfirmationDialog("Delete Feat", message, "Yes", "No", null);

                    if (result == true)
                    {
                        _compendium.DeleteFeat(_selectedFeat.FeatModel.Id);

                        FeatListItemViewModel listItem = _feats.FirstOrDefault(x => x.FeatModel.Id == _selectedFeat.FeatModel.Id);
                        if (listItem != null)
                        {
                            _feats.Remove(listItem);
                        }

                        _selectedFeat = null;

                        _compendium.SaveFeats();

                        OnPropertyChanged(nameof(SelectedFeat));

                        if (_editFeatXML != null)
                        {
                            CancelEditFeat();
                        }
                    }
                }
                else
                {
                    _dialogService.ShowConfirmationDialog("Unable Delete Feat", "Feat is in use by a character.", "OK", null, null);
                }
            }
        }
示例#17
0
        public async Task <IHttpActionResult> Post([FromBody] FeatViewModel value)
        {
            var postedFeat = await Task.Run(() => _featService.AddFeat(value));

            return(CreatedAtRoute("FeatGet", new { id = postedFeat.Id }, postedFeat));
        }