Example #1
0
        public async Task <IActionResult> Post([FromBody] NewHero newHero)
        {
            //TODO : Rev
            try
            {
                var heroEntity = new HeroEntity
                {
                    Id   = Guid.NewGuid(),
                    Name = newHero.Name
                };

                await _heroesRepository.CreateHero(heroEntity).ConfigureAwait(false);

                var hero = Mapper.Map <Hero>(heroEntity);

                return(Created(hero));
            }
            catch (Exception ex)
            {
                if (ex is ArgumentNullException)
                {
                    return(BadRequest());
                }

                _logger.LogError(ex, "Error creating hero.");
                return(StatusCode(500));
            }
        }
        public async Task <IActionResult> AddHeroes([FromBody] HeroesManagementDto hero)
        {
            //nieuwzglenianie case sensitivity
            hero.HeroName = hero.HeroName.ToLower();

            // sprawdzenie czy taki bohater juz istnieje
            if (await _repo.ValidateHeroName(hero.HeroName))
            {
                return(BadRequest("Taka nazwa bohatera już istnieje"));
            }

            // dodanie bohatera
            var heroToCreate = new Heroes
            {
                HeroName = hero.HeroName,
                GameId   = hero.GameId
            };

            var createdHero = await _repo.CreateHero(heroToCreate);


            // dodanie statystyk bohatera
            var heroStats = new HeroeStats
            {
                AbilityPower          = hero.AbilityPower,
                ApLifeSteal           = hero.ApLifeSteal,
                Armour                = hero.Armour,
                ArmourPenetration     = hero.ArmourPenetration,
                ArmourPenetrationProc = hero.ArmourPenetrationProc,
                AttackDamage          = hero.AttackDamage,
                AttackSpeed           = hero.AttackSpeed,
                CooldownReduction     = hero.CooldownReduction,
                CriticalChance        = hero.CriticalChance,
                HitPoints             = hero.HitPoints,
                HitPointsRegen        = hero.HitPointsRegen,
                LifeSteal             = hero.LifeSteal,
                MagicPenetration      = hero.MagicPenetration,
                MagicPenetrationProc  = hero.MagicPenetrationProc,
                MagicResistance       = hero.MagicResistance,
                Mana          = hero.Mana,
                ManaRegen     = hero.ManaRegen,
                MovementSpeed = hero.MovementSpeed,
                Range         = hero.Range,
                Tenacity      = hero.Tenacity,
                HeroId        = heroToCreate.Id
            };

            var createdItemStats = await _repo.CreateHeroStats(heroStats);

            return(StatusCode(201));
        }