public async Task <IActionResult> Edit(string id, [Bind("Code,Zone,RuralOrUrban,Rate")] PostcodeModel postcode) { if (id != postcode.Postcode) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(postcode); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostcodeExists(postcode.Postcode)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(postcode)); }
private async Task SavePostCode(PostcodeModel postcode) { if (!postcode.Latitude.HasValue || !postcode.Longitude.HasValue) { Console.WriteLine($"Skipping postcode '{postcode.Postcode}' because it has a null location"); //TODO: Do another lookup on first part of postcode } else { Console.WriteLine($"Saving {postcode.Postcode} at {postcode.Latitude}, {postcode.Longitude}"); var location = new LocationModel { Postcode = postcode.Postcode, Longitude = postcode.Longitude.Value, Latitude = postcode.Latitude.Value, Country = postcode.Country, Region = postcode.Region, AdminCounty = postcode.Admin_County, AdminDistrict = postcode.Admin_District, AdminDistrictCode = postcode.Codes.Admin_District }; await _locationWriter.SaveAsync(location); } }
private async Task <PostcodeModel> CheckLocationAndRetryUsingOutcodeAsync(PostcodeModel postcodeModel) { if (postcodeModel != null && (!postcodeModel.Latitude.HasValue || !postcodeModel.Longitude.HasValue)) { postcodeModel = await GetPostcodeAsync(postcodeModel.OutCode); } return(postcodeModel); }
public void GivenIHaveEnteredInvalidPostcodeIntoTheTextbox(string p0) { _postcodeModel = new PostcodeModel() { Postcode = p0 }; _restaurantService.Setup(x => x.GetRestaurantsAsync(It.IsAny <string>())).ReturnsAsync(new List <RestaurantModel>() { }); _homeController = new HomeController(_restaurantService.Object); }
public async Task <IActionResult> Create([Bind("Code,Zone,RuralOrUrban,Rate")] PostcodeModel postcode) { if (ModelState.IsValid) { _context.Add(postcode); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(postcode)); }
// GET: Postcodes/Details/CV346GB public string Details(string postcode) { PostcodeModel postcodeDetails = (from p in _context.Postcodes.Include("RateDetails") //join r in _context.Rates on p.RateId equals r.RateId where p.Postcode == postcode select p) .FirstOrDefault(); //; return(postcodeDetails.ToJSONString()); }
/// <summary> /// Find all restaurant by postcode /// </summary> /// <param name="postcodeModel">Postcode model includes postcode value</param> /// <returns>Partial view of restaurant list</returns> public async Task <ActionResult> Restaurants(PostcodeModel postcodeModel) { var restaurants = new List <RestaurantModel>(); if (ModelState.IsValid) { //get restautrants by postcode and order by avarage rating desc restaurants = await _client.GetRestaurantsAsync(postcodeModel.Postcode) .ContinueWith(t => t.Result.OrderByDescending(r => r.RatingStars).ToList()); } return(PartialView(restaurants)); }