public async Task <ActionResult <CharacterSkill> > PostCharacterSkill(CharacterSkill characterSkill) { _repository.Insert(characterSkill); await _repository.Save(); return(CreatedAtAction("GetCharacterSkill", new { id = characterSkill.Id }, characterSkill)); }
private async Task GetCharSkills() { try { var charSkills = await _charSkillService.Get(); if (charSkills != null) { foreach (var charSkill in charSkills) { // Ensure that charSKill is not already present and necessary items are stored if (await CharSkillExists(charSkill.SkillId, charSkill.CharacterId) || await _characterRepository.GetCharacter(charSkill.CharacterId) == null || await _skillRepository.GetSkill(charSkill.SkillId) == null) { continue; } _charSkillRepository.AddSkillToCharacter(charSkill.SkillId, charSkill.CharacterId); await _charSkillRepository.Save(); } } } catch (BrokenCircuitException) { _logger.LogWarning("Broken Circuit"); } }
public async Task <IActionResult> AddSkill(int id, [Bind("CharId, SkillId")] CharacterSkillViewModel charSkill) { var skill = await _skillRepository.GetSkill(charSkill.SkillId); var character = await _characterRepository.GetCharacter(charSkill.CharId); if (skill != null && character != null) { if (character.Xp - skill.XpCost >= 0) { // Subtract cost from character, add and save to link table character.Xp -= skill.XpCost; _charSkillRepository.AddSkillToCharacter(charSkill.SkillId, id); await _charSkillRepository.Save(); // Update Local and API _characterRepository.UpdateCharacter(character); await _characterRepository.Save(); await _characterService.UpdateCharacter(character); return(RedirectToAction(nameof(Details), new { id })); } } return(View()); }
public async Task <IActionResult> DeleteConfirmed(int id) { var characterSkill = await _characterSkillRepository.Get(id); await _characterSkillRepository.Delete(id); await _characterSkillRepository.Save(); return(RedirectToAction(nameof(Index))); }