예제 #1
0
        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");
            }
        }
예제 #2
0
        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());
        }