Example #1
0
        public async Task <IActionResult> Index()
        {
            BuildDeckViewModel model = await _ihelperApi.getAllCards();

            return(View(model));
        }
Example #2
0
        public async Task <BuildDeckViewModel> getCards(List <string> types)
        {
            int         countMinion                     = 0;
            int         countSpell                      = 0;
            int         countEnchantment                = 0;
            int         countHero                       = 0;
            int         countHeroPower                  = 0;
            int         countWeapon                     = 0;
            List <Card> CardListMinion                  = new List <Card>();
            List <Card> CardListSpell                   = new List <Card>();
            List <Card> CardListEnchantment             = new List <Card>();
            List <Card> CardListWeapon                  = new List <Card>();
            List <Card> CardListHero                    = new List <Card>();
            List <Card> CardListHeroPower               = new List <Card>();
            List <BuildDeckStatViewModel> viewModelList = new List <BuildDeckStatViewModel>();

            HttpResponseMessage response = await client.GetAsync("https://api.hearthstonejson.com/v1/27845/frFR/cards.json");

            JArray jsonParseList = new JArray();

            if (response.IsSuccessStatusCode)
            {
                jsonParseList = await response.Content.ReadAsAsync <JArray>();

                foreach (var item in jsonParseList)
                {
                    if (item["type"] != null)
                    {
                        string   jsonType      = item["type"].Value <string>();
                        string   idCard        = item["id"].Value <string>();
                        CardType jsonTypeClass = (CardType)Enum.Parse(typeof(CardType), jsonType);
                        foreach (var type in types)
                        {
                            CardType typeClass = (CardType)Enum.Parse(typeof(CardType), type);
                            if (jsonTypeClass == typeClass)
                            {
                                if (typeClass == CardType.ENCHANTMENT)
                                {
                                    EnchantmentCard Card = item.ToObject <EnchantmentCard>();
                                    countEnchantment++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListEnchantment.Add(Card);
                                }
                                else if (typeClass == CardType.HERO)
                                {
                                    HeroCard Card = item.ToObject <HeroCard>();
                                    if (Card.Armor != 0)
                                    {
                                        countHero++;
                                        Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                        CardListHero.Add(Card);
                                    }
                                }
                                else if (typeClass == CardType.HERO_POWER)
                                {
                                    HeroPowerCard Card = item.ToObject <HeroPowerCard>();
                                    countHeroPower++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListHeroPower.Add(Card);
                                }
                                else if (typeClass == CardType.MINION)
                                {
                                    MinionCard Card = item.ToObject <MinionCard>();
                                    countMinion++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListMinion.Add(Card);
                                }
                                else if (typeClass == CardType.SPELL)
                                {
                                    SpellCard Card = item.ToObject <SpellCard>();
                                    countSpell++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListSpell.Add(Card);
                                }
                                else if (typeClass == CardType.WEAPON)
                                {
                                    WeaponCard Card = item.ToObject <WeaponCard>();
                                    countWeapon++;
                                    Card.LinkPicture = "https://art.hearthstonejson.com/v1/render/latest/frFR/512x/" + idCard + ".png";
                                    CardListWeapon.Add(Card);
                                }
                            }
                        }
                    }
                }

                CardStat cardStatMinion      = new CardStat("minion", countMinion);
                CardStat cardStatSpell       = new CardStat("spell", countSpell);
                CardStat cardStatHero        = new CardStat("hero", countHero);
                CardStat cardStatHeroPower   = new CardStat("hero_power", countHeroPower);
                CardStat cardStatWeapon      = new CardStat("weapon", countWeapon);
                CardStat cardStatEnchantment = new CardStat("enchantment", countEnchantment);

                var statViewModelMinion = new BuildDeckStatViewModel
                {
                    CardStat = cardStatMinion,
                    Cards    = CardListMinion
                };
                var statViewModelSpell = new BuildDeckStatViewModel
                {
                    CardStat = cardStatSpell,
                    Cards    = CardListSpell
                };
                var statViewModelHero = new BuildDeckStatViewModel
                {
                    CardStat = cardStatHero,
                    Cards    = CardListHero
                };
                var statViewModelHeroPower = new BuildDeckStatViewModel
                {
                    CardStat = cardStatHeroPower,
                    Cards    = CardListHeroPower
                };
                var statViewModelWeapon = new BuildDeckStatViewModel
                {
                    CardStat = cardStatWeapon,
                    Cards    = CardListWeapon
                };
                var statViewModelEnchantment = new BuildDeckStatViewModel
                {
                    CardStat = cardStatEnchantment,
                    Cards    = CardListEnchantment
                };

                BuildDeckStatViewModel[] rangeStatViewModel =
                {
                    statViewModelEnchantment,
                    statViewModelHero,
                    statViewModelHeroPower,
                    statViewModelWeapon,
                    statViewModelSpell,
                    statViewModelMinion
                };

                viewModelList.AddRange(rangeStatViewModel);

                var model = new BuildDeckViewModel
                {
                    Stats = viewModelList
                };
                return(model);
            }
            else
            {
                return(null);
            }
        }