public CharacterViewModel UpdateCharacter(CharacterViewModel viewModel) { var character = _dndRepository.GetSingle <Character>(a => a.Id == viewModel.Id); if (character == null) { throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Character))); } character.Name = viewModel.Name; character.Level = viewModel.Level; character.IdCAligment = viewModel.IdCAligment; character.IdClass = viewModel.IdClass; character.PlayerName = viewModel.PlayerName; character.IdRace = viewModel.IdRace; character.ExperiencePoints = viewModel.ExperiencePoints; character.ProficiencyBonus = viewModel.ProficiencyBonus; character.ArmorClass = viewModel.ArmorClass; character.Initiative = viewModel.Initiative; character.Speed = viewModel.Speed; character.MaxHitPoints = viewModel.MaxHitPoints; character.CopperCoins = viewModel.CopperCoins; character.SilverCoins = viewModel.SilverCoins; character.ElectrumCoins = viewModel.ElectrumCoins; character.GoldCoins = viewModel.GoldCoins; _dndRepository.Update(character); _dndRepository.Commit(); return(Mapper.Map <Character, CharacterViewModel>(_dndRepository.GetSingle <Character>(a => a.Id == viewModel.Id, false, a => a.Aligment))); }
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 EquipmentViewModel UpdateEquipment(EquipmentViewModel viewModel) { var entity = _dndRepository.GetSingle <Equipment>(a => a.IdEquipment == viewModel.IdEquipment); if (entity == null) { throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Equipment))); } entity.IdCTypeEquipment = viewModel.IdCTypeEquipment; entity.Name = viewModel.Name; entity.Cost = viewModel.Cost; _dndRepository.Update(entity); _dndRepository.Commit(); return(GetEquipmentById(entity.IdEquipment)); }