示例#1
0
        public IActionResult AddTeam([FromBody] Team newTeam)
        {
            var team = newTeam;

            context.Teams.Add(team);
            context.SaveChanges();
            return(new OkObjectResult(team));
        }
示例#2
0
        public IActionResult AddTrainer([FromBody] Trainer newTrainer)
        {
            Trainer trainer = newTrainer;

            if (context.Trainers.Where(t => t.UserId == trainer.UserId).Any())
            {
                return(BadRequest());
            }

            context.Trainers.Add(trainer);
            context.SaveChanges();
            return(new OkObjectResult(trainer));
        }
        public IActionResult GetPokemonById(int id)
        {
            var pokemon = context.Pokemons.Include(t => t.Trainer).SingleOrDefault(t => t.PokemonId == id);

            if (pokemon == null)
            {
                return(NotFound());
            }

            context.Pokemons.Remove(pokemon);
            context.SaveChanges();

            return(new OkObjectResult(pokemon));
        }
        public IActionResult CreateTrainer([FromBody] Trainer newTrainer)
        {
            //newTrainer.Id = 3;
            Trainer trainer = new Trainer();

            trainer.Id     = newTrainer.Id;
            trainer.Name   = newTrainer.Name;
            trainer.League = newTrainer.League;
            trainer.Cards  = newTrainer.Cards;
            context.Trainers.Add(trainer);
            context.SaveChanges();
            return(new OkObjectResult(trainer));
            //return OkObjectResult("GetTrainer", new { id = newTrainer.Id });
        }
示例#5
0
        public IActionResult CreatePokemon([FromBody] Pokemon newPokemon)
        {
            //newTrainer.Id = 3;
            Pokemon pokemon = new Pokemon();

            pokemon.Id     = pokemon.Id;
            pokemon.Name   = newPokemon.Name;
            pokemon.Rarity = newPokemon.Rarity;
            pokemon.Image  = newPokemon.Image;
            pokemon.Hp     = newPokemon.Hp;
            pokemon.Type   = newPokemon.Type;
            context.Pokemons.Add(pokemon);
            context.SaveChanges();
            return(new OkObjectResult(pokemon));
            //return OkObjectResult("GetTrainer", new { id = newTrainer.Id });
        }
示例#6
0
        //public static Pokemon SearchPokemonByName(string pokemonName)
        //{
        //    var pokemonList = DatabaseLoaderActions.LoadAllPokemonFromJSON();
        //    return pokemonList.FirstOrDefault(x => x.Name == pokemonName);
        //}

        public static Move AddMove(Move move)
        {
            using (var db = new PokeContext())
            {
                if (db.Moves.FirstOrDefault(x => x.Name == move.Name) == null)
                {
                    move = db.Moves.Add(move).Entity;
                    db.SaveChanges();
                }
                return(move);
            }
        }
示例#7
0
 public static Pokemon AddPokemon(Pokemon pokemon)
 {
     using (var db = new PokeContext())
     {
         if (db.Pokemons.FirstOrDefault(x => x.Name == pokemon.Name) == null)
         {
             pokemon = db.Pokemons.Add(pokemon).Entity;
             db.SaveChanges();
         }
         return(pokemon);
     }
 }
        /*Main methods*/
        #region Main methods
        public static void UpdatePokedex(IWebDriver driver)
        {
            driver.Navigate().GoToUrl(StartingPokedexIndex);
            var wait       = new WebDriverWait(driver, TimeSpan.FromSeconds(240));
            var loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(NextPokemonElementXpath)));
            int MaximumPokemonIdAvailable = driver.FindElements(By.XPath(PokemonListDropDownOptionsXpath)).Count - 1;

            for (int i = 0; i < MaximumPokemonIdAvailable; i++)
            {
                loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(PokemonNameIDXpath)));
                IWebElement nameIDElement = driver.FindElement(By.XPath(PokemonNameIDXpath));
                loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(NextPokemonElementXpath)));
                IWebElement nextPokemon = driver.FindElement(By.XPath(NextPokemonElementXpath));
                var         pokemonID   = GetPokemonID(nameIDElement);
                var         pokemonName = GetPokemonName(nameIDElement);
                using (var db = new PokeContext())
                {
                    if (db.Pokemons.FirstOrDefault(x => x.Name == pokemonName) != null)
                    {
                        nextPokemon.Click();
                        Console.WriteLine($"Pokémon already in database ({pokemonName}). Skipping...");
                        continue;
                    }
                }
                loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(PokemonTypesXpath)));
                IList <IWebElement> typesElement = driver.FindElements(By.XPath(PokemonTypesXpath));
                loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(PokemonBaseStatsTableElementsXpath)));
                IList <IWebElement> baseStatsElements = driver.FindElements(By.XPath(PokemonBaseStatsTableElementsXpath));
                loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(PokemonMaxStatsTableElementsXpath)));
                IList <IWebElement> maxStatsElements = driver.FindElements(By.XPath(PokemonMaxStatsTableElementsXpath));
                loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(PokemonMovesByLevelElementsXpath)));
                IList <IWebElement> movesByLevelElements = driver.FindElements(By.XPath(PokemonMovesByLevelElementsXpath));
                //loadWaiter = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(PokemonAvailableTMsElementsXpath)));
                //IList<IWebElement> availableTMsElements = driver.FindElements(By.XPath(PokemonAvailableTMsElementsXpath));
                Pokemon pokemon = new Pokemon()
                {
                    Name = pokemonName
                };
                using (var db = new PokeContext())
                {
                    InjectPokemonHP(pokemon, StatType.Base, baseStatsElements);
                    InjectPokemonATK(pokemon, StatType.Base, baseStatsElements);
                    InjectPokemonDEF(pokemon, StatType.Base, baseStatsElements);
                    InjectPokemonSPATK(pokemon, StatType.Base, baseStatsElements);
                    InjectPokemonSPDEF(pokemon, StatType.Base, baseStatsElements);
                    InjectPokemonSPD(pokemon, StatType.Base, baseStatsElements);
                    InjectPokemonHP(pokemon, StatType.Max, maxStatsElements);
                    InjectPokemonATK(pokemon, StatType.Max, maxStatsElements);
                    InjectPokemonDEF(pokemon, StatType.Max, maxStatsElements);
                    InjectPokemonSPATK(pokemon, StatType.Max, maxStatsElements);
                    InjectPokemonSPDEF(pokemon, StatType.Max, maxStatsElements);
                    InjectPokemonSPD(pokemon, StatType.Max, maxStatsElements);
                    InjectPokemonElementTypes(pokemon, typesElement, db);
                    InjectPokemonMovesByLevel(pokemon, movesByLevelElements, db);
                    if (db.Pokemons.FirstOrDefault(x => x.Name == pokemon.Name) == null)
                    {
                        pokemon = db.Pokemons.Add(pokemon).Entity;
                        db.SaveChanges();
                    }
                    Console.WriteLine($"New Pokémon added to database:#{pokemon.ID}-{pokemon.Name}");
                    nextPokemon.Click();
                }
            }
        }