/// <summary>
        ///  This service gets the list of cities and their properties, including their overall rating.
        ///  The cities are returned in a JSON array.
        /// </summary>
        /// <returns>Returns the list of cities and their properties.</returns>
        public IHttpActionResult GetCities()
        {
            getCitiesResponse response = new getCitiesResponse();

            try
            {
                List <CityDto> cities = db.Cities.Include("cities").Select(i => new CityDto
                {
                    CityId              = i.CityId,
                    CityName            = i.CityName,
                    CityStateOrProvince = i.CityStateOrProvince,
                    CityCountry         = i.CityCountry,
                    CityImgUri          = i.CityImgUri,
                    CityRating          = (float)(Math.Ceiling(i.RateCities.Where(r => r.CityId == i.CityId).Average(r => r.Rating) * 2) / 2)
                }).ToList();

                response.cities = new List <CityDto>();
                response.cities = cities;
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            return(Ok(response));
        }
        public async Task <IList <CityDto> > getCityListAsync(CancellationToken aCancelationToken = default(CancellationToken))
        {
            HttpRequestMessage request  = new HttpRequestMessage(HttpMethod.Get, "cities/");
            getCitiesResponse  cityList = await SendAndReadAsAsync <getCitiesResponse>(request, aCancelationToken);

            return(cityList?.cities);
        }
        public async Task <ActionResult> Index()
        {
            Uri KateHelloWorldApisUri = new Uri(ConfigurationManager.AppSettings["KateHelloWorldApisUri"]);
            IKateHelloWorldServiceProvider _KateHelloWorldHelper = new KateHelloWorldServiceProvider(KateHelloWorldApisUri, null, null);

            getCitiesResponse citiesResponse = new getCitiesResponse();

            try
            {
                citiesResponse.cities = await _KateHelloWorldHelper.getCityListAsync();
            }
            catch (Exception ex)
            {
                //For dev purposes, we will show the error
                ViewBag.Error = ex.Message;
            }

            return(View(citiesResponse.cities));
        }