public List <CharacterSkillViewModel> SetSkillsToCharacter(int idCharacter, List <CharacterSkillViewModel> skills) { var character = GetCharacterById(idCharacter); if (character == null) { throw new Exception(string.Format(Resources.ValidationMessages.EntityM_Error_NotFound, nameof(Character))); } _dndRepository.DeleteWhere <CharacterSkill>(a => a.IdCharacter == idCharacter); var entity = Mapper.Map <List <CharacterSkillViewModel>, List <CharacterSkill> >(skills); _dndRepository.AddRange(entity); _dndRepository.Commit(); List <CharacterSkill> entityList = _dndRepository.GetAllWhere(new List <System.Linq.Expressions.Expression <Func <CharacterSkill, bool> > >() { a => a.IdCharacter == idCharacter }).ToList(); return(Mapper.Map <List <CharacterSkill>, List <CharacterSkillViewModel> >(entityList)); }
public SpellbookViewModel SetSpellsToSpellbook(List <SpellViewModel> spells, int idSpellbook) { _repository.DeleteWhere <SpellSpellbook>(a => a.IdSpell == idSpellbook); foreach (var spell in spells) { var entity = new SpellSpellbookViewModel { IdSpell = spell.Id, IdSpellbook = idSpellbook }; _repository.Add(entity); } _repository.Commit(); var spellBook = _repository.GetSingle <Spellbook>(a => a.Id == idSpellbook, false, a => a.SpellbookSpells); return(Mapper.Map <Spellbook, SpellbookViewModel>(spellBook)); }