Beispiel #1
0
        /// <summary>
        /// Set the spells of a character
        /// </summary>
        /// <param name="idCharacter"></param>
        /// <param name="spells"></param>
        /// <returns>SpellKnowViewModel</returns>
        public SpellKnowViewModel SetSpellsKnown(int idCharacter, SpellKnowViewModel spells)
        {
            var character = _dndRepository.GetSingle <Character>(a => a.Id == idCharacter);

            if (character == null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Character)));
            }
            _dndRepository.DeleteWhere <CharacterSpell>(a => a.IdCharacter == idCharacter);
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.Cantrips.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel1.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel2.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel3.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel4.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel5.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel6.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel7.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel8.ToList()));
            _dndRepository.AddRange(AddSCharacterSpells(idCharacter, spells.SpellsLevel9.ToList()));


            _dndRepository.Commit();

            return(GetCharacterSpell(idCharacter));
        }
Beispiel #2
0
        /// <summary>
        /// Get the spells of a character by given entity
        /// </summary>
        /// <param name="character"></param>
        /// <returns>SpellKnowViewModel</returns>
        public SpellKnowViewModel GetCharacterSpell(Character character)
        {
            var spells = _dndRepository.GetAllWhere(new List <System.Linq.Expressions.Expression <Func <Spell, bool> > >()
            {
                a => character.CharacterSpells.Where(s => s.IdSpell == a.Id).First() != null
            }).ToList();
            var characterSpells = new SpellKnowViewModel();

            foreach (var spell in spells)
            {
                var spellVM = Mapper.Map <Spell, SpellViewModel>(spell);
                switch (spell.Level)
                {
                case 1:
                    characterSpells.SpellsLevel1.Add(spellVM);
                    break;

                case 2:
                    characterSpells.SpellsLevel2.Add(spellVM);
                    break;

                case 3:
                    characterSpells.SpellsLevel3.Add(spellVM);
                    break;

                case 4:
                    characterSpells.SpellsLevel4.Add(spellVM);
                    break;

                case 5:
                    characterSpells.SpellsLevel5.Add(spellVM);
                    break;

                case 6:
                    characterSpells.SpellsLevel6.Add(spellVM);
                    break;

                case 7:
                    characterSpells.SpellsLevel7.Add(spellVM);
                    break;

                case 8:
                    characterSpells.SpellsLevel8.Add(spellVM);
                    break;

                case 9:
                    characterSpells.SpellsLevel9.Add(spellVM);
                    break;

                case 0:
                default:
                    characterSpells.Cantrips.Add(spellVM);
                    break;
                }
            }
            return(characterSpells);
        }
Beispiel #3
0
        /// <summary>
        /// Get the spells of a character by given id
        /// </summary>
        /// <param name="idCharacter"></param>
        /// <returns>SpellKnowViewModel</returns>
        public SpellKnowViewModel GetCharacterSpell(int idCharacter)
        {
            var character = _dndRepository.GetSingle <Character>(a => a.Id == idCharacter, false, a => a.CharacterSpells);

            if (character == null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Character)));
            }

            var spells = _dndRepository.GetAllWhere(new List <System.Linq.Expressions.Expression <Func <Spell, bool> > >()
            {
                a => character.CharacterSpells.Where(s => s.IdSpell == a.Id).First() != null
            }).ToList();
            var characterSpells = new SpellKnowViewModel();

            foreach (var spell in spells)
            {
                var spellVM = Mapper.Map <Spell, SpellViewModel>(spell);
                switch (spell.Level)
                {
                case 1:
                    characterSpells.SpellsLevel1.Add(spellVM);
                    break;

                case 2:
                    characterSpells.SpellsLevel2.Add(spellVM);
                    break;

                case 3:
                    characterSpells.SpellsLevel3.Add(spellVM);
                    break;

                case 4:
                    characterSpells.SpellsLevel4.Add(spellVM);
                    break;

                case 5:
                    characterSpells.SpellsLevel5.Add(spellVM);
                    break;

                case 6:
                    characterSpells.SpellsLevel6.Add(spellVM);
                    break;

                case 7:
                    characterSpells.SpellsLevel7.Add(spellVM);
                    break;

                case 8:
                    characterSpells.SpellsLevel8.Add(spellVM);
                    break;

                case 9:
                    characterSpells.SpellsLevel9.Add(spellVM);
                    break;

                case 0:
                default:
                    characterSpells.Cantrips.Add(spellVM);
                    break;
                }
            }
            return(characterSpells);
        }