private async Task ImportTrainerCardsFromSet(object arg) { using (var client = new WebClient()) { var json = await client.DownloadStringTaskAsync($"https://api.pokemontcg.io/v1/cards?setCode={SelectedSet.SetCode}&supertype=Trainer").ConfigureAwait(false); var headers = client.ResponseHeaders; int cardsFound = int.Parse(headers.Get("Count")); int pageSize = int.Parse(headers.Get("Page-Size")); if (cardsFound > pageSize) { //TODO } foreach (var card in JsonConvert.DeserializeObject <PokemonTcgSdk.Trainer>(json).Cards) { TrainerCards.Add(new TrainerCard { Name = card.Name, ImageUrl = card.ImageUrlHiRes, Completed = false, SetCode = card.SetCode, CardId = NetworkId.Generate() }); } SelectedTrainerCard = TrainerCards.First(); } }
private void AddTrainerCard(object obj) { TrainerCards.Add(new TrainerCard() { Name = "New Trainer", CardId = NetworkId.Generate() }); SelectedTrainerCard = TrainerCards.Last(); }
private void UpdateSetFilter() { if (SelectedSet == null) { FilteredCards = TrainerCards.ToList(); return; } FilteredCards = TrainerCards.Where(card => card.SetCode == SelectedSet.SetCode).ToList(); }
internal async Task Load() { if (!File.Exists("Data/trainers.json")) { return; } var json = await File.ReadAllTextAsync("Data/trainers.json"); TrainerCards.Clear(); foreach (var trainer in Serializer.Deserialize <List <TrainerCard> >(json).OrderBy(x => x.SetCode).ThenBy(x => x.Name)) { TrainerCards.Add(trainer); } }