Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task <Dota2PlayerListModel.RootObject> GetDota2List(string gameid)
        {
            //Dota2Model.RootObject dota2 = null;
            //string url = "https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?league_id=" + gameid + "&key=10608324BF5A95D48936E6471867E64E&matches_requested=5";
            string url = "https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?match_id=" + gameid + "&key=10608324BF5A95D48936E6471867E64E";

            Dota2PlayerListModel.RootObject data = null;

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    var jsonResponse = response.Content.ReadAsStringAsync().Result;
                    data = JsonConvert.DeserializeObject <Dota2PlayerListModel.RootObject>(jsonResponse);
                }
            }

            return(data);
        }
        public async System.Threading.Tasks.Task <ActionResult> Dota2Details()
        {
            //Dota2LeagueModel.RootObject dota2leagues = null;
            //dota2leagues = await new Dota2Repository().Dota2LeagueList();


            List <Dota2League> dota2leagues     = new Dota2Repository().Dota2LeagueList();
            List <object>      dota2gamematchid = new List <object>();

            List <Dota2ViewModel> d2vmList = new List <Dota2ViewModel>();


            foreach (var res in dota2leagues)
            {
                Dota2ViewModel d2vm = new Dota2ViewModel();

                Dota2PlayerModel.RootObject dota2game = await new Dota2Repository().GetDota2Game(res.leagueid);


                //leaguesname.Add(res.name);
                d2vm.leaguename = res;
                //d2vm.match = dota2game;
                List <Dota2PlayerMatchModel> d2pm = new List <Dota2PlayerMatchModel>();
                foreach (var match in dota2game.result.matches)
                {
                    if (match.series_type != 0 || match.dire_team_id != 0 && match.radiant_team_id != 0)
                    {
                        //string m = match.match_id.ToString();
                        //dota2gamematchid.Add(m);
                        Dota2PlayerMatchModel d2 = new Dota2PlayerMatchModel();
                        string d2tmradian        = "未知";
                        string d2tmdire          = "未知";

                        d2tmradian = await new Dota2Repository().GetDota2Teams(match.radiant_team_id.ToString());
                        d2tmdire   = await new Dota2Repository().GetDota2Teams(match.dire_team_id.ToString());


                        // gpvm.TeamA = teamlist.Where(p => p.sn == gamepost.TeamASn).FirstOrDefault();
                        d2.radiant_team = d2tmradian;
                        d2.dire_team    = d2tmdire;
                        d2.strar_time   = (new DateTime(1970, 1, 1, 0, 0, 0)).AddHours(8).AddSeconds(match.start_time);
                        d2.timeid       = match.series_id;
                        d2.match_id     = match.match_id;
                        Dota2PlayerListModel.RootObject dota2gamelist = await new Dota2Repository().GetDota2List(match.match_id.ToString());
                        d2.match_name      = dota2gamelist.result.dire_name + " VS " + dota2gamelist.result.radiant_name;
                        d2.Dota2PlayerList = dota2gamelist;

                        if (d2.d2BO == null)
                        {
                            var bo = 1;
                            foreach (var item in d2pm)
                            {
                                if (d2.timeid == item.timeid)
                                {
                                    bo += 1;
                                }
                            }
                            d2.d2BO = bo;
                        }

                        d2pm.Add(d2);
                    }
                }
                foreach (var itemcount in d2pm)
                {
                    var d2count = 0;
                    for (int d2i = 0; d2i < d2pm.Count(); d2i++)
                    {
                        if (itemcount.timeid == d2pm[d2i].timeid)
                        {
                            d2count++;
                        }
                    }
                    itemcount.d2BOcount = d2count;
                }


                d2vm.d2match = d2pm;
                d2vmList.Add(d2vm);
            }


            return(View(d2vmList));
        }