Example #1
0
        public async Task <ActionResult> SearchByGenre(GenreObj genreObj)
        {
            // make another games API call
            // call for Games, with a title of 'titleToSearchBy'
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("https://api.rawg.io/api/genres");

            HttpResponseMessage response = await client.GetAsync("?search=" + genreObj.Title);

            List <Item> itemsToChooseFrom = new List <Item>();

            if (response.IsSuccessStatusCode)
            {
                string data = await response.Content.ReadAsStringAsync();

                JObject jsonResults = JsonConvert.DeserializeObject <JObject>(data);


                for (int i = 0; i < 10; i++)
                {
                    JToken name     = jsonResults["results"][i]["name"];
                    JToken Released = jsonResults["results"][i]["released"];


                    Item randomItem = new Item();
                    randomItem.Name     = name.ToString();
                    randomItem.Released = Released.ToString();



                    itemsToChooseFrom.Add(randomItem);
                }
            }

            return(View("GamesIndex", itemsToChooseFrom));
        }
Example #2
0
        public ActionResult SearchByGenre()
        {
            GenreObj input = new GenreObj();

            return(View(input));
        }