static async Task <SearchListings> RunAsync(ListingAction action) { httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd( "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); return(await GetFlatAsync(action)); }
static void Main() { try { var listingAction = new ListingAction(new ListingFilters(ListingTypes.Buy, "Chelsea")); var result = RunAsync(listingAction).Result; var flats = result.Response.Listings.Select(x => new Flat { Price = x.Price.ToString(), FlatLocation = x.Title.ToString(), BedNum = x.BedNum.ToString(), BathNum = x.BathNum.ToString(), Summary = x.Summary.ToString() }); using (var context = new FlatDbContext()) { context.Flats.AddRange(flats); context.SaveChanges(); //context } } catch (ArgumentException e) { Console.WriteLine($"Something is going wrong: {e.Message}"); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static async Task <SearchListings> GetFlatAsync(ListingAction action) { var response = await httpClient.GetAsync(new Uri($"{baseUrl}{action.ListingUrl}")); return(await response.Content.ReadAsAsync <SearchListings>()); }