Exemplo n.º 1
0
        public async Task <IActionResult> SearchUsername(SearchViewModel searchViewModel)
        {
            if (ModelState.IsValid)
            {
                FindUser      findUser      = new FindUser(searchViewModel.Username);
                EpicNameModel epicNameModel = await findUser.FindUserID();

                StatsProcessor statsProcessor = new StatsProcessor();
                EpicStatsModel epicStatsModel = await statsProcessor.LoadStats(epicNameModel);

                if (epicStatsModel.Global_Stats != null & epicStatsModel.Name != null)
                {
                    ViewBag.name       = epicStatsModel.Name;
                    ViewBag.statistics = epicStatsModel.Global_Stats;
                    return(View());
                }
                ViewBag.name = "User does not exist.";
            }
            return(View());
        }
Exemplo n.º 2
0
        // Get player stats
        public async Task <EpicStatsModel> LoadStats(EpicNameModel epicNameModel)
        //returning 0 right now, need to pass a string as a parameter to convert username to their user id to check their stats.
        {
            HttpClient httpClient = new HttpClient();
            string     url        = $"https://fortniteapi.io/stats?account={epicNameModel.Account_id}";

            httpClient.DefaultRequestHeaders.Add("Authorization", "0e235bf6-1954f433-5e4caaf7-f6deb034");

            try
            {
                HttpResponseMessage response = await httpClient.GetAsync(url);

                EpicStatsModel stats = await response.Content.ReadAsAsync <EpicStatsModel>();

                //response.Content = json
                //RootObject stats = //JsonConvert.DeserializeObject<RootObject>(response.Content);

                return(stats);
            }
            catch (HttpRequestException)
            {
                return(new EpicStatsModel());
            }
        }