Example #1
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)));
        }
Example #2
0
        public CharacterViewModel CreateCharacter(CharacterViewModel viewModel)
        {
            var character = Mapper.Map <CharacterViewModel, Character>(viewModel);

            if (_dndRepository.GetSingle <Character>(a => a.Id == viewModel.Id, true) != null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_AlredyExist, nameof(Character)));
            }
            _dndRepository.Add(character);

            _dndRepository.Commit();
            character = _dndRepository.GetSingle <Character>(a => a.Id == character.Id, false, a => a.Aligment);
            return(Mapper.Map <Character, CharacterViewModel>(character));
        }
        public EquipmentViewModel CreateEquipment(EquipmentViewModel viewModel)
        {
            var entity = _dndRepository.GetSingle <Equipment>(a => a.IdEquipment == viewModel.IdEquipment);

            if (entity != null)
            {
                throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_AlredyExist, nameof(Equipment)));
            }
            else
            {
                entity = Mapper.Map <EquipmentViewModel, Equipment>(viewModel);
            }
            _dndRepository.Add(entity);
            _dndRepository.Commit();
            entity = _dndRepository.GetSingle <Equipment>(a => a.IdEquipment == entity.IdEquipment, false, a => a.TypeEquipment);
            return(Mapper.Map <Equipment, EquipmentViewModel>(entity));
        }