Ejemplo n.º 1
0
        private void ExportSpell(SpellViewModel spellViewModel)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter   = "Word Document|*.docx|XML Document|*.xml";
            saveFileDialog.Title    = "Save Spell";
            saveFileDialog.FileName = spellViewModel.Name;

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

                    if (ext == ".docx")
                    {
                        _documentService.CreateWordDoc(saveFileDialog.FileName, spellViewModel.SpellModel);
                    }
                    else if (ext == ".xml")
                    {
                        string xml = _xmlExporter.FormatXMLWithHeader(_xmlExporter.GetXML(spellViewModel.SpellModel));
                        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 spell.", "OK", null, null);
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, SpellViewModel viewModel)
        {
            var spell = new Spell()
            {
                Id          = id,
                Name        = viewModel.Name,
                Level       = viewModel.Level,
                School      = viewModel.School,
                CastingTime = viewModel.CastingTime,
                Range       = viewModel.Range,
                Verbal      = viewModel.Verbal,
                Somatic     = viewModel.Somatic,
                Materials   = viewModel.Materials,
                Duration    = viewModel.Duration,
                Ritual      = viewModel.Ritual,
                Description = viewModel.Description
            };

            if (_spellRepo.Update(spell))
            {
                return(RedirectToAction("Select", "Spell",
                                        routeValues: new { id = spell.Id }));
            }
            else
            {
                ModelState.AddModelError("", "Unable to update Spell");
                return(View(viewModel));
            }
        }
Ejemplo n.º 3
0
        private void SelectPrevious()
        {
            if (_spells.Any())
            {
                SpellListItemViewModel selected = _spells.FirstOrDefault(x => x.IsSelected);

                foreach (SpellListItemViewModel spell in _spells)
                {
                    spell.IsSelected = false;
                }

                if (selected == null)
                {
                    _spells[_spells.Count - 1].IsSelected = true;
                    _selectedSpell = new SpellViewModel(_spells[_spells.Count - 1].SpellModel);
                }
                else
                {
                    int index = Math.Max(_spells.IndexOf(selected) - 1, 0);
                    _spells[index].IsSelected = true;
                    _selectedSpell            = new SpellViewModel(_spells[index].SpellModel);
                }

                OnPropertyChanged(nameof(SelectedSpell));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Select(int id, int?spellbookId)
        {
            Spell spell = _spellRepo.Get(id);

            // Maybe eventually set up Mapper DI.
            //var mapper = new Mapper(config);
            //SpellViewModel viewModel = mapper.Map<SpellViewModel>(spell);

            var viewModel = new SpellViewModel();

            viewModel.Id          = spell.Id;
            viewModel.Name        = spell.Name;
            viewModel.Level       = spell.Level;
            viewModel.School      = spell.School;
            viewModel.CastingTime = spell.CastingTime;
            viewModel.Range       = spell.Range;
            viewModel.Verbal      = spell.Verbal;
            viewModel.Somatic     = spell.Somatic;
            viewModel.Materials   = spell.Materials;
            viewModel.Ritual      = spell.Ritual;
            viewModel.Description = spell.Description;

            if (spellbookId != null)
            {
                viewModel.SpellbookId = spellbookId;
            }

            return(View(viewModel));
        }
Ejemplo n.º 5
0
        private void EditSpell(SpellViewModel spellModel)
        {
            _editSpellXML = spellModel.XML;

            OnPropertyChanged(nameof(EditingSpellXML));
            OnPropertyChanged(nameof(IsEditingSpell));
        }
Ejemplo n.º 6
0
        public ActionResult Create(int?spellbookId)
        {
            var viewModel = new SpellViewModel();

            viewModel.SpellbookId = spellbookId;
            return(View(viewModel));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PostSpell([FromBody] SpellViewModel spellViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }


            var entity = new DB.Data.Entities.Spells
            {
                Name         = spellViewModel.Name,
                Description  = spellViewModel.Description,
                Components   = spellViewModel.Components,
                Level        = spellViewModel.Level,
                Range        = spellViewModel.Range,
                Casting_Time = spellViewModel.Casting_Time,
                Duration     = spellViewModel.Duration,
                School       = spellViewModel.School,
            };



            await this.context.Set <DB.Data.Entities.Spells>().AddAsync(entity);

            try
            {
                await this.context.SaveChangesAsync();
            }
            catch (Exception ee)
            {
                return(this.BadRequest("Registro no grabado, controlar."));
            }

            return(Ok(entity));
        }
Ejemplo n.º 8
0
        public async Task <SpellViewModel> CreateSpell([FromBody] SpellViewModel spellVM)
        {
            var domainModel = spellVM.ToDomainModel();

            if (spellVM.SpellId > 0) // editing an existing feature
            {
                //make sure they're the author of this feature
                var existingSpell = await this.dbCtx.Spells.FirstOrDefaultAsync(f => f.Player.Id == userSession.Player.Id && f.Id == spellVM.SpellId);

                if (existingSpell != null)
                {
                    //yep, it's theirs
                    existingSpell.Delisted = true;
                }
            }
            domainModel.Id = 0;

            dbCtx.Attach(userSession.Player);
            domainModel.Player      = userSession.Player;
            domainModel.CreatedAtMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            dbCtx.Spells.Add(domainModel);

            await dbCtx.SaveChangesAsync();

            domainModel.Player = userSession.Player;

            return(domainModel.ToViewModel());
        }
Ejemplo n.º 9
0
        private static void SpellInjection(SpellViewModel spellVM, Champion champion, string spellType)
        {
            var spellDb = champion.Spells.FirstOrDefault(x => x.Id == spellVM.Id && x.SpellType == spellType);

            if (spellDb == null)
            {
                spellDb           = new Spell();
                spellDb.SpellType = spellType;
                champion.Spells.Add(spellDb);
            }
            spellDb.Name        = spellVM.Name;
            spellDb.Description = spellVM.Description;

            if (spellVM.Image != null && spellVM.Image.Length > 0)
            {
                using (var ms = new MemoryStream())
                {
                    spellVM.Image.CopyTo(ms);
                    var bytearray = ms.ToArray();
                    spellDb.Logo = string.Format("data:{1};base64,{0}",
                                                 Convert.ToBase64String(bytearray),
                                                 spellVM.Image.ContentType);
                }
            }
        }
Ejemplo n.º 10
0
        public SpellViewModel CreateSpell(SpellViewModel viewModel)
        {
            var entity = Mapper.Map <SpellViewModel, Spell>(viewModel);

            _repository.Add(entity);
            _repository.Commit();
            return(Mapper.Map <Spell, SpellViewModel>(_repository.GetSingle <Spell>(a => a.Id == entity.Id)));
        }
        public SpellViewModel CreateSpell(SpellViewModel viewModel)
        {
            var entity = Mapper.Map <SpellViewModel, Spell>(viewModel);

            _dndRepository.Add(entity);
            _dndRepository.Commit();

            return(GetSpellById(entity.Id));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> PutSpell(int id, [FromBody] SpellViewModel spellViewModel)
        {
            var entity = await this.context.Set <DB.Data.Entities.Spells>().FindAsync(id);

            entity.Name = spellViewModel.Name;
            this.context.Entry(entity).State = EntityState.Modified;
            await this.context.SaveChangesAsync();

            return(Ok(entity));
        }
Ejemplo n.º 13
0
        public SpellViewModel UdpateSpell(int id, SpellViewModel spell)
        {
            var originalSpell = _spellRepository.GetById(id);

            SpellMapper.MapModelToEntity(spell, originalSpell);
            originalSpell.ModifiedBy = "TEST";
            var updatedSpell = _spellRepository.Update(originalSpell);

            return(SpellMapper.MapEntityToModel(updatedSpell));
        }
Ejemplo n.º 14
0
        public SpellViewModel AddSpell(SpellViewModel spell)
        {
            var spellToAdd = SpellMapper.MapModelToEntity(spell);

            spellToAdd.CreatedBy = "TEST";
            spellToAdd.SeedData  = false;
            var addedSpell = _spellRepository.Add(spellToAdd);

            return(SpellMapper.MapEntityToModel(addedSpell));
        }
Ejemplo n.º 15
0
        public ActionResult Delete(int id)
        {
            Spell spell = _spellRepo.Get(id);

            var viewModel = new SpellViewModel();

            viewModel.Id    = spell.Id;
            viewModel.Name  = spell.Name;
            viewModel.Level = spell.Level;

            return(View(viewModel));
        }
Ejemplo n.º 16
0
 public static Spell ToDomainModel(this SpellViewModel spellVM)
 {
     return(new Spell
     {
         CreatedAtMS = spellVM.CreatedAtMS,
         Description = spellVM.Description,
         EnergyCost = spellVM.EnergyCost,
         Id = spellVM.SpellId,
         MovementCost = spellVM.MovementCost,
         Name = spellVM.Name,
         RegenTimeInRounds = spellVM.RegenTimeInRounds
     });
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Shows details dialog
        /// </summary>
        public void ShowDetailsDialog(SpellViewModel spellViewModel)
        {
            ModalDialog modalDialog = new ModalDialog();

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

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

            ShowDialog(modalDialog);
        }
Ejemplo n.º 18
0
        public ActionResult Delete(int id, SpellViewModel viewModel)
        {
            bool success = _spellRepo.Delete(id);

            if (success)
            {
                return(RedirectToAction("Index", "Spell"));
            }
            else
            {
                ModelState.AddModelError("", "Unable to delete Spell");
                return(View(viewModel));
            }
        }
Ejemplo n.º 19
0
        private void SelectSpell(SpellListItemViewModel spellItem)
        {
            bool selectSpell = true;

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

            if (selectSpell)
            {
                foreach (SpellListItemViewModel item in _spells)
                {
                    item.IsSelected = false;
                }
                spellItem.IsSelected = true;

                _selectedSpell = new SpellViewModel(spellItem.SpellModel);
                OnPropertyChanged(nameof(SelectedSpell));
            }
        }
        public IActionResult GetSpellById(int id)
        {
            var viewModel = new SpellViewModel();

            try
            {
                viewModel = _spellLogicHandler.GetSpellById(id);
            }
            catch (Exception ex)
            {
                _responseFormatter.SetError(ex);
                return(new BadRequestObjectResult(_responseFormatter.GetResponse()));
            }
            _responseFormatter.Add("spell", viewModel);
            return(new OkObjectResult(_responseFormatter.GetResponse()));
        }
Ejemplo n.º 21
0
        public SpellViewModel UpdateSpell(SpellViewModel viewModel)
        {
            var entity = _repository.GetSingle <Spell>(a => a.Id == viewModel.Id);

            if (entity == null)
            {
                throw new Exception("Spell doesnt exist.");
            }
            entity.Level     = viewModel.Level;
            entity.Name      = viewModel.Name;
            entity.SpellType = viewModel.SpellType;
            _repository.Update(entity);
            _repository.Commit();
            entity = _repository.GetSingle <Spell>(a => a.Id == viewModel.Id);
            return(Mapper.Map <Spell, SpellViewModel>(entity));
        }
        public SpellViewModel UpdateSpell(SpellViewModel viewModel)
        {
            var entity = _dndRepository.GetSingle <Spell>(a => a.Id == viewModel.Id);

            if (entity == null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Spell)));
            }
            entity.Name        = viewModel.Name;
            entity.Description = viewModel.Description;

            _dndRepository.Update(entity);
            _dndRepository.Commit();

            return(GetSpellById(viewModel.Id));
        }
Ejemplo n.º 23
0
        public SpellBookPage()
        {
            viewModel           = new SpellBookPageViewModel();
            viewModel.SpellList = new ObservableCollection <SpellViewModel>();

            this.InitializeComponent();

            Game.Charakter.CharakterSpellBook.AddSpell(new DSALib.Charakter.Other.Spell("Test", Game.Charakter.Attribute.UsedAttributs)
            {
            });
            var spellList = Game.Charakter.CharakterSpellBook.GetSpellList();

            foreach (var item in spellList)
            {
                var model = new SpellViewModel(item);
                viewModel.SpellList.Add(model);
            }
        }
Ejemplo n.º 24
0
        public ActionResult Edit(int id)
        {
            var spell     = _spellRepo.Get(id);
            var viewModel = new SpellViewModel()
            {
                Name        = spell.Name,
                Level       = spell.Level,
                School      = spell.School,
                CastingTime = spell.CastingTime,
                Range       = spell.Range,
                Verbal      = spell.Verbal,
                Somatic     = spell.Somatic,
                Materials   = spell.Materials,
                Duration    = spell.Duration,
                Ritual      = spell.Ritual,
                Description = spell.Description
            };

            return(View(viewModel));
        }
Ejemplo n.º 25
0
        public ActionResult Create(int?spellbookId, SpellViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var spell = new Spell()
                {
                    Name        = viewModel.Name,
                    Level       = viewModel.Level,
                    School      = viewModel.School,
                    CastingTime = viewModel.CastingTime,
                    Range       = viewModel.Range,
                    Verbal      = viewModel.Verbal,
                    Somatic     = viewModel.Somatic,
                    Materials   = viewModel.Materials,
                    Duration    = viewModel.Duration,
                    Ritual      = viewModel.Ritual,
                    Description = viewModel.Description
                };

                var success = _spellRepo.Add(spell);
                if (success.HasValue)
                {
                    if (spellbookId != null)
                    {
                        return(RedirectToAction("AddSpell", "Spellbook", new { id = spellbookId }));
                    }
                    return(RedirectToAction("Index", "Spell"));
                }
                else
                {
                    ModelState.AddModelError("", "Unable to add spell.");
                }
            }

            return(View(viewModel));
        }
Ejemplo n.º 26
0
 public SpellPage(Spell spell)
 {
     InitializeComponent();
     BindingContext = new SpellViewModel(spell);
 }
Ejemplo n.º 27
0
        private bool SaveEditSpell()
        {
            bool saved = false;

            try
            {
                SpellModel model = _xmlImporter.GetSpell(_editSpellXML);

                if (model != null)
                {
                    model.Id = _selectedSpell.SpellModel.Id;
                    _compendium.UpdateSpell(model);
                    _selectedSpell = new SpellViewModel(model);

                    SpellListItemViewModel oldListItem = _spells.FirstOrDefault(x => x.SpellModel.Id == model.Id);
                    if (oldListItem != null)
                    {
                        if (_spellSearchService.SearchInputApplies(_spellSearchInput, model))
                        {
                            oldListItem.UpdateModel(model);
                        }
                        else
                        {
                            _spells.Remove(oldListItem);
                        }
                    }

                    _editSpellXML          = null;
                    _editHasUnsavedChanges = false;

                    SortSpells();

                    _compendium.SaveSpells();

                    OnPropertyChanged(nameof(SelectedSpell));
                    OnPropertyChanged(nameof(EditingSpellXML));
                    OnPropertyChanged(nameof(IsEditingSpell));
                    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);
        }
Ejemplo n.º 28
0
        private void Add()
        {
            bool addSpell = true;

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

            if (addSpell)
            {
                string xml = @"<name>New Spell</name>
									<level></level>
									<school></school>
									<ritual></ritual>
									<time></time>
									<range></range>
									<components></components>
									<duration></duration>
									<classes></classes>
									<text></text>
									<roll></roll>"                                    ;

                SpellModel spellModel = _xmlImporter.GetSpell(xml);

                _compendium.AddSpell(spellModel);

                if (_spellSearchService.SearchInputApplies(_spellSearchInput, spellModel))
                {
                    SpellListItemViewModel listItem = new SpellListItemViewModel(spellModel, _stringService);
                    _spells.Add(listItem);
                    foreach (SpellListItemViewModel item in _spells)
                    {
                        item.IsSelected = false;
                    }
                    listItem.IsSelected = true;
                }

                _selectedSpell = new SpellViewModel(spellModel);

                _editSpellXML = spellModel.XML;

                SortSpells();

                _compendium.SaveSpells();

                OnPropertyChanged(nameof(EditingSpellXML));
                OnPropertyChanged(nameof(IsEditingSpell));
                OnPropertyChanged(nameof(SelectedSpell));
            }
        }
Ejemplo n.º 29
0
        private void Copy()
        {
            if (_selectedSpell != null)
            {
                bool copySpell = true;

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

                if (copySpell)
                {
                    SpellModel newSpell = new SpellModel(_selectedSpell.SpellModel);
                    newSpell.Name += " (copy)";
                    newSpell.Id    = Guid.NewGuid();
                    newSpell.XML   = newSpell.XML.Replace("<name>" + _selectedSpell.SpellModel.Name + "</name>",
                                                          "<name>" + newSpell.Name + "</name>");

                    _compendium.AddSpell(newSpell);

                    if (_spellSearchService.SearchInputApplies(_spellSearchInput, newSpell))
                    {
                        SpellListItemViewModel listItem = new SpellListItemViewModel(newSpell, _stringService);
                        _spells.Add(listItem);
                        foreach (SpellListItemViewModel item in _spells)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedSpell = new SpellViewModel(newSpell);

                    SortSpells();

                    _compendium.SaveSpells();

                    OnPropertyChanged(nameof(SelectedSpell));
                }
            }
        }
Ejemplo n.º 30
0
        private void Delete()
        {
            if (_selectedSpell != null)
            {
                bool canDelete = true;

                foreach (CharacterModel character in _compendium.Characters)
                {
                    foreach (SpellbookModel spellbook in character.Spellbooks)
                    {
                        foreach (SpellbookEntryModel spellbookEntry in spellbook.Spells)
                        {
                            if (spellbookEntry.Spell != null && spellbookEntry.Spell.Id == _selectedSpell.SpellModel.Id)
                            {
                                canDelete = false;
                                break;
                            }
                        }

                        if (!canDelete)
                        {
                            break;
                        }
                    }

                    if (!canDelete)
                    {
                        break;
                    }
                }

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

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

                    if (result == true)
                    {
                        _compendium.DeleteSpell(_selectedSpell.SpellModel.Id);

                        SpellListItemViewModel listItem = _spells.FirstOrDefault(x => x.SpellModel.Id == _selectedSpell.SpellModel.Id);
                        if (listItem != null)
                        {
                            _spells.Remove(listItem);
                        }

                        _selectedSpell = null;

                        _compendium.SaveSpells();

                        OnPropertyChanged(nameof(SelectedSpell));

                        if (_editSpellXML != null)
                        {
                            CancelEditSpell();
                        }
                    }
                }
                else
                {
                    _dialogService.ShowConfirmationDialog("Unable Delete Spell", "Spell is in use by a character.", "OK", null, null);
                }
            }
        }