private List <SelectListItem> GetSports(LeaguesContainer input, string sport)
        {
            List <SelectListItem> listToReturn = new List <SelectListItem>();
            HashSet <string>      tempResult   = new HashSet <string>();

            foreach (var sp in input.Leagues)
            {
                if (!tempResult.Contains(sp.strSport))
                {
                    tempResult.Add(sp.strSport);
                }
            }
            foreach (var item in tempResult.ToList())
            {
                if (item == sport)
                {
                    listToReturn.Add(new SelectListItem {
                        Text = item, Value = item, Selected = true
                    });
                }
                else
                {
                    listToReturn.Add(new SelectListItem {
                        Text = item, Value = item, Selected = false
                    });
                }
            }
            return(listToReturn);
        }
Ejemplo n.º 2
0
        public async Task <LeaguesContainer> GetAllLagues()
        {
            string json = "";

            using WebClient client = new WebClient();
            json = await client.DownloadStringTaskAsync($@"https://www.thesportsdb.com/api/v1/json/1/all_leagues.php").ConfigureAwait(true);

            LeaguesContainer container = Newtonsoft.Json.JsonConvert.DeserializeObject <LeaguesContainer>(json);

            if (container == null)
            {
                return(null);
            }
            return(container);
        }