public IActionResult CreatePokemon(CreateTeamPokemonViewModel pokemonTeamDetail, int pokemonTeamId)
        {
            if (!this.ModelState.IsValid)
            {
                CreateTeamPokemonViewModel model = new CreateTeamPokemonViewModel()
                {
                    AllPokemon = this.FillPokemonList(pokemonTeams[pokemonTeamId - 1]),
                    AllNatures = this.dataService.GetObjects <Nature>("Name"),
                    NatureId   = this.dataService.GetObjectByPropertyValue <Nature>("Name", "Serious").Id,
                    GameId     = pokemonTeamDetail.GameId,
                    Level      = 100,
                    Happiness  = 255,
                };

                return(this.View(model));
            }

            PokemonTeam pokemonTeam = pokemonTeams[pokemonTeamId - 1];

            Pokemon pokemon = this.dataService.GetPokemonById(pokemonTeamDetail.PokemonId);

            if (pokemon.GenderRatioId == 10)
            {
                pokemonTeamDetail.Gender = null;
            }

            int pokemonTeamDetailId = this.dataService.AddPokemonTeamDetail(pokemonTeamDetail);

            pokemonTeam.InsertPokemon(this.dataService.GetPokemonTeamDetail(pokemonTeamDetailId));

            this.dataService.UpdatePokemonTeam(pokemonTeam);

            return(this.RedirectToAction("PokemonTeams", "User"));
        }
        /// <summary>
        /// Creates a pokemon team from a string in Pokemon Showndown's export format.
        /// </summary>
        /// <param name="importedTeam">The pokemon string in Pokemon Showdown's export format.</param>
        /// <param name="userId">The id of the user.</param>
        private void CreateTeamFromImport(string importedTeam, int userId)
        {
            string teamName = importedTeam.Split("===\r\n")[0];
            string pokemonString;

            if (teamName.IndexOf("===") != -1)
            {
                teamName = string.Concat(teamName, "===");
                int teamNameStart = teamName.IndexOf("] ");
                if (teamNameStart == -1)
                {
                    teamNameStart = 4;
                }
                else
                {
                    teamNameStart += 2;
                }

                int teamNameTo = teamName.LastIndexOf(" ===");
                teamName      = teamName.Substring(teamNameStart, teamNameTo - teamNameStart);
                pokemonString = string.Concat("\r\n", importedTeam.Split("===\r\n")[1]);
            }
            else
            {
                teamName      = "Import From Pokemon Showdown";
                pokemonString = importedTeam;
            }

            PokemonTeam pokemonTeam = new PokemonTeam()
            {
                PokemonTeamName = teamName,
                UserId          = userId,
            };
            List <string> pokemonList         = pokemonString.Split("\r\n\r\n").ToList();
            List <string> filteredPokemonList = new List <string>();

            foreach (var p in pokemonList)
            {
                if (!string.IsNullOrEmpty(p) && filteredPokemonList.Count < 6)
                {
                    filteredPokemonList.Add(p);
                }
            }

            // Used to ensure that there are no issues when creating the pokemon detail.
            List <PokemonTeamDetailViewModel> pokemonDetailList = new List <PokemonTeamDetailViewModel>();

            foreach (var p in filteredPokemonList)
            {
                pokemonDetailList.Add(this.CreatePokemonDetailFromImport(p));
            }

            foreach (var p in pokemonDetailList)
            {
                if (p.EVs != null)
                {
                    p.PokemonTeamEVId = this.dataService.AddPokemonTeamEV(p.EVs);
                }

                if (p.IVs != null)
                {
                    p.PokemonTeamIVId = this.dataService.AddPokemonTeamIV(p.IVs);
                }

                if (p.Moveset != null)
                {
                    p.PokemonTeamMovesetId = this.dataService.AddPokemonTeamMoveset(p.Moveset);
                }

                int pokemonId = this.dataService.AddPokemonTeamDetail(p);
                pokemonTeam.InsertPokemon(this.dataService.GetPokemonTeamDetail(pokemonId));
            }

            string generationId = importedTeam.Split("===\r\n")[0];

            this.dataService.FillPokemonTeam(pokemonTeam);
            List <Game> availableGames = this.dataService.GetAvailableGames(pokemonTeam);

            if (generationId.IndexOf("[gen") != -1)
            {
                int generationStart = generationId.IndexOf(" [");
                int generationEnd   = generationId.IndexOf("] ");
                generationId = generationId.Substring(generationStart, generationEnd - generationStart);
                int genId = Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace(generationId, "[^0-9]+", string.Empty));
                if (availableGames.Find(x => x.Id == genId) != null)
                {
                    pokemonTeam.GameId = availableGames.Last(x => x.GenerationId == genId).Id;
                }
                else
                {
                    pokemonTeam.GameId = availableGames.Last().Id;
                }
            }
            else
            {
                Game newestGame = availableGames.Last();
                pokemonTeam.GameId = newestGame.Id;
            }

            if (pokemonTeam.FirstPokemon != null)
            {
                pokemonTeam.FirstPokemon = null;
            }

            if (pokemonTeam.SecondPokemon != null)
            {
                pokemonTeam.SecondPokemon = null;
            }

            if (pokemonTeam.ThirdPokemon != null)
            {
                pokemonTeam.ThirdPokemon = null;
            }

            if (pokemonTeam.FourthPokemon != null)
            {
                pokemonTeam.FourthPokemon = null;
            }

            if (pokemonTeam.FifthPokemon != null)
            {
                pokemonTeam.FifthPokemon = null;
            }

            if (pokemonTeam.SixthPokemon != null)
            {
                pokemonTeam.SixthPokemon = null;
            }

            this.dataService.AddPokemonTeam(pokemonTeam);
        }