public async Task <List <Competitor> > DriverRanking()
        {
            List <Competitor> DriverList = new List <Competitor>();

            //F1ViewModel model = FormulaOne
            //For documentation go to:
            //https://developer.sportradar.com/docs/read/racing/Formula_1_v2#competitor-profile

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(
                    "http://api.sportradar.us/formula1/trial/v2/en/sport_events/sr:stage:324771/summary.json?api_key=cbrg93g2tbafunheua84ay5h");


                response.EnsureSuccessStatusCode();
                var responseBody = await response.Content.ReadAsStringAsync();

                var formulaOne = FormulaOne.FromJson(responseBody);

                foreach (var competitor in formulaOne.Stage.Competitors)
                {
                    DriverList.Add(new Competitor {
                        Name = competitor.Name, Nationality = competitor.Nationality, Team = competitor.Team, Points = competitor.Points, Result = competitor.Result
                    });
                }

                return(DriverList);
            }
        }
Пример #2
0
        public async Task <ActionResult> NextRace()
        {
            F1ViewModel model = new F1ViewModel();

            //F1ViewModel model = FormulaOne
            //For documentation go to:
            //https://developer.sportradar.com/docs/read/racing/Formula_1_v2#competitor-profile

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(
                    "http://api.sportradar.us/formula1/trial/v2/en/sport_events/sr:stage:324771/summary.json?api_key=cbrg93g2tbafunheua84ay5h");


                response.EnsureSuccessStatusCode();
                var responseBody = await response.Content.ReadAsStringAsync();

                var formulaOne = FormulaOne.FromJson(responseBody);

                model.FormulaOne = formulaOne;
            }

            string getIsFinished = $"SELECT IsFinished FROM race WHERE RaceID = '{1}'";

            model.raceFinished = db.getID(getIsFinished);

            if (model.raceFinished == 1)
            {
                int raceID = 1;
                model.raceResult = db.getRaceResult(raceID);
                model.raceResult = model.raceResult.OrderBy(P => P.Position).ToList();
            }


            return(View(model));
        }