public void CargarDatos() { // Comprueba si está en local el Stat del pokemon amigo string urlStat = GlobalVar.friendCoach.pokemons[GlobalVar.pokAmigo].stats.Where(x => x.stat.name == "hp").First().stat.url; if (realm.All <StatRealm>().Where(x => x.id == int.Parse(urlStat.Substring(31, (urlStat.Length - 1 - 31)))).Count() == 0) { // Obtiene el Stat del pokemon amigo y lo mapea a la clase Stat propia GlobalVar.friendStat = Mapeo.StatToStatRealm(rep.ObtenerStat(GlobalVar.friendCoach.pokemons[GlobalVar.pokAmigo].stats.Where(x => x.stat.name == "hp").First().stat.url), "es", "en"); // Guarda en local el Stat del pokemon amigo realm.Write(() => { realm.Add(GlobalVar.friendStat); }); } else { // Recupera el Stat del pokemon amigo guardado en local GlobalVar.friendStat = realm.All <StatRealm>().Where(x => x.id == int.Parse(urlStat.Substring(31, (urlStat.Length - 1 - 31)))).First(); } // Carga los ataques del amigo GlobalVar.friendMoves.Clear(); for (int count = 0; count < GlobalVar.friendCoach.user.pokemons[GlobalVar.pokAmigo].moves.Count(); count++) { // Comprueba si está en local el Move del pokemon amigo string urlFriendMove = GlobalVar.friendCoach.user.pokemons[GlobalVar.pokAmigo].moves[count].url; if (realm.All <MoveRealm>().Where(x => x.id == int.Parse(urlFriendMove.Substring(31, (urlFriendMove.Length - 1 - 31)))).Count() == 0) { // Obtiene el Move del pokemon amigo y lo mapea a la clase Move propia GlobalVar.friendMoves.Add(Mapeo.MoveToMoveRealm(rep.ObtenerMove(GlobalVar.friendCoach.user.pokemons[GlobalVar.pokAmigo].moves[count].url), "es", "en")); // Guarda en local el Move del pokemon amigo realm.Write(() => { realm.Add(GlobalVar.friendMoves.Last()); }); } else { // Recupera el Move del pokemon amigo guardado en local GlobalVar.friendMoves.Add(realm.All <MoveRealm>().Where(x => x.id == int.Parse(urlFriendMove.Substring(31, (urlFriendMove.Length - 1 - 31)))).First()); } } // Carga los ataques del enemigo GlobalVar.enemyMoves.Clear(); for (int count = 0; count < GlobalVar.enemyCoach.user.pokemons[GlobalVar.pokEnemigo].moves.Count(); count++) { // Comprueba si está en local el Move del pokemon enemigo string urlEnemyMove = GlobalVar.enemyCoach.user.pokemons[GlobalVar.pokEnemigo].moves[count].url; if (realm.All <MoveRealm>().Where(x => x.id == int.Parse(urlEnemyMove.Substring(31, (urlEnemyMove.Length - 1 - 31)))).Count() == 0) { // Obtiene el Move del pokemon enemigo y lo mapea a la clase Move propia GlobalVar.enemyMoves.Add(Mapeo.MoveToMoveRealm(rep.ObtenerMove(GlobalVar.enemyCoach.user.pokemons[GlobalVar.pokEnemigo].moves[count].url), "es", "en")); // Guarda en local el Move del pokemon enemigo realm.Write(() => { realm.Add(GlobalVar.enemyMoves.Last()); }); } else { // Recupera el Move del pokemon enemigo guardado en local GlobalVar.enemyMoves.Add(realm.All <MoveRealm>().Where(x => x.id == int.Parse(urlEnemyMove.Substring(31, (urlEnemyMove.Length - 1 - 31)))).First()); } } }