/// <summary>
        /// Gets the resturants by delivery area.
        /// </summary>
        /// <param name="outcode">The outcode.</param>
        /// <returns></returns>
        public ResturantResult GetResturantsByDeliveryArea(Outcode outcode)
        {
            outcode.ThrowIfNull(nameof(outcode));
            var getResturantResult = new ResturantResult();

            // Cleaning up this
            var requestUrl = $"{BaseUri}" + RestaurantRoute + "?q=" + outcode.Value;
            using (var client = CreateHttpClient())
            {
                try
                {
                    var response = client.GetAsync(requestUrl).Result;

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        var responseContent = response.Content.ReadAsStringAsync().Result;
                        getResturantResult = FormatSearchResults(responseContent);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception: {ex.Message}");
                    getResturantResult.Successful = false;
                }

                return getResturantResult;
            }
        }
 public async void SearchForRestaurant()
 {
     var outcode = new Outcode
     {
         Value = Outcode
     };
     
     var result = await restaurantService.GetResturantsByDeliveryAreaAsync(outcode);
     if (result.Successful)
         this.Resturants = result.Restaurants;
     else
         Debug.WriteLine("woops! Problem!");
 }
Example #3
0
        private static void SearchForRestaurant()
        {
            System.Console.WriteLine("Enter an outcode");
            var rawOutcode = System.Console.ReadLine();
            var outcode = new Outcode
            {
                Value = rawOutcode
            };

            var restaurantService = new HttpRestaurantService();

            var searchResults = restaurantService.GetResturantsByDeliveryArea(outcode);

            if (searchResults.Successful)
            {
                PrintRestrauntResults(searchResults);
            }
            else
            {
                System.Console.WriteLine("It seems there was a problem, please try again later.");
            }
        }
 /// <summary>
 /// Gets the resturants by delivery area asynchronous.
 /// </summary>
 /// <param name="outcode">The outcode.</param>
 /// <returns></returns>
 public Task<ResturantResult> GetResturantsByDeliveryAreaAsync(Outcode outcode)
 {
     return Task.Run(() => GetResturantsByDeliveryArea(outcode));
 }