Ejemplo n.º 1
0
        public async Task <HeroesManagementDto> GetHeroesToModify(int heroId)
        {
            HeroesManagementDto heroToReturn = new HeroesManagementDto();

            Heroes hero = await _context.Heroes.FirstOrDefaultAsync(x => x.Id == heroId);

            HeroeStats heroStats = await _context.HeroeStats.FirstOrDefaultAsync(x => x.HeroId == hero.Id);


            heroToReturn.AbilityPower          = heroStats.AbilityPower;
            heroToReturn.ApLifeSteal           = heroStats.ApLifeSteal;
            heroToReturn.Armour                = heroStats.Armour;
            heroToReturn.ArmourPenetration     = heroStats.ArmourPenetration;
            heroToReturn.ArmourPenetrationProc = heroStats.ArmourPenetrationProc;
            heroToReturn.AttackDamage          = heroStats.AttackDamage;
            heroToReturn.AttackSpeed           = heroStats.AttackSpeed;
            heroToReturn.CooldownReduction     = heroStats.CooldownReduction;
            heroToReturn.CriticalChance        = heroStats.CriticalChance;
            heroToReturn.HeroName              = hero.HeroName;
            heroToReturn.HitPoints             = heroStats.HitPoints;
            heroToReturn.HitPointsRegen        = heroStats.HitPointsRegen;
            heroToReturn.LifeSteal             = heroStats.LifeSteal;
            heroToReturn.MagicPenetration      = heroStats.MagicPenetration;
            heroToReturn.MagicPenetrationProc  = heroStats.MagicPenetrationProc;
            heroToReturn.MagicResistance       = heroStats.MagicResistance;
            heroToReturn.Mana          = heroStats.Mana;
            heroToReturn.ManaRegen     = heroStats.ManaRegen;
            heroToReturn.MovementSpeed = heroStats.MovementSpeed;
            heroToReturn.Range         = heroStats.Range;
            heroToReturn.Tenacity      = heroStats.Tenacity;

            return(heroToReturn);
        }
        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));
        }
        public async Task <IActionResult> ModifyHeroes([FromBody] HeroesManagementDto hero)
        {
            //nieuwzglenianie case sensitivity
            hero.HeroName = hero.HeroName.ToLower();


            var heroIdFromDB = await _repo.GetHeroId(hero.HeroName);


            // 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        = heroIdFromDB
            };

            var createdItemStats = await _repo.ModifyHeroStats(heroStats);

            return(StatusCode(201));
        }