Beispiel #1
0
        internal void Update(IEnumerable <PokemonData> pokemons)
        {
            foreach (var item in pokemons)
            {
                var existing = Pokemons.FirstOrDefault(x => x.Id == item.Id);

                if (existing != null)
                {
                    existing.Displayed = Filter.Check(existing);
                    existing.UpdateWith(item);
                }
                else
                {
                    var pokemonDataViewModel = new PokemonDataViewModel(Session, item);
                    pokemonDataViewModel.Displayed = Filter.Check(pokemonDataViewModel);

                    Pokemons.Add(pokemonDataViewModel);
                    Task.Run(async() =>
                    {
                        GeoLocation geoLocation = await GeoLocation.FindOrUpdateInDatabase(pokemonDataViewModel.PokemonData.CapturedCellId);
                        if (geoLocation != null)
                        {
                            pokemonDataViewModel.GeoLocation = geoLocation;
                        }
                    });
                }
            }

            // Remove missing pokemon
            List <PokemonDataViewModel> modelsToRemove = new List <PokemonDataViewModel>();

            foreach (var item in Pokemons)
            {
                var existing = pokemons.FirstOrDefault(x => x.Id == item.Id);
                if (existing == null)
                {
                    modelsToRemove.Add(item);
                }
            }

            foreach (var model in modelsToRemove)
            {
                Pokemons.Remove(model);
            }
        }
Beispiel #2
0
        internal bool Check(PokemonDataViewModel item)
        {
            if (!string.IsNullOrEmpty(Name))
            {
                if (!Name.ToLower().Contains(item.PokemonId.ToString().ToLower()))
                {
                    return(false);
                }
            }

            if (item.IV < MinIV || item.IV > MaxIV)
            {
                return(false);
            }
            if (item.Level < MinLevel || item.Level > MaxLevel)
            {
                return(false);
            }
            if (item.CP < MinCP || item.CP > MaxCP)
            {
                return(false);
            }
            return(true);
        }