Esempio n. 1
0
        /// <summary>
        /// this initial version of GetAllPlanetsAsync used a dedicated implementation not reusable with other methods,
        /// but we're keeping it because it was an acceptable solution before implementing other API endpoints
        /// </summary>
        public static async Task <IEnumerable <Planet> > GetAllPlanetsAsyncOld(this IStarWarsApi api)
        {
            List <Planet> results = new List <Planet>();

            int page = 0;

            do
            {
                page++;
                ApiResult <List <Planet> > result = await api.GetPlanetsAsync(page);

                results.AddRange(result.Data);
                if (result.Next == null)
                {
                    break;
                }
            } while (true);

            return(results);
        }
Esempio n. 2
0
 /// <summary>
 /// this uses our more generic GetAllAsync method. Use this pattern going forward
 /// </summary>
 public static async Task <IEnumerable <Planet> > GetAllPlanetsAsync(this IStarWarsApi api) => await GetAllAsync(api, (api, page) => api.GetPlanetsAsync(page));