Example #1
0
        public async Task <StarShip> GetRandomStarShipExcludingNamesUsedBefore(List <string> namesUsedBefore)
        {
            Result starships;
            var    starshipsNotUsedBefore = new List <StarShip>();

            var response = await _httpClient.GetAsync("api/starships/");

            response.EnsureSuccessStatusCode();
            string content = await response.Content.ReadAsStringAsync();

            starships = JsonConvert.DeserializeObject <Result>(content);

            if (starships.Results.Any())
            {
                foreach (var starship in starships.Results)
                {
                    if (!namesUsedBefore.Contains(starship.name))
                    {
                        starshipsNotUsedBefore.Add(starship);
                    }
                }

                int maxRangeNumber = starshipsNotUsedBefore.Count() - 1;
                int randomNumber   = RandomGeneratorHelper.RandomNumberGen(maxRangeNumber);

                return(starshipsNotUsedBefore[randomNumber]);
            }

            return(null);
        }
Example #2
0
        public async Task <StarShip> GetRandomStarShip()
        {
            Result starships;

            var response = await _httpClient.GetAsync("api/starships/");

            response.EnsureSuccessStatusCode();
            string content = await response.Content.ReadAsStringAsync();

            starships = JsonConvert.DeserializeObject <Result>(content);

            if (starships.Results.Any())
            {
                int maxRangeNumber = starships.Results.Count() - 1;
                int randomNumber   = RandomGeneratorHelper.RandomNumberGen(maxRangeNumber);

                return(starships.Results.ToList()[randomNumber]);
            }

            return(null);
        }