public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,Email,VSOStreet,VSOCity,VSOState,VSOZipCode")] VSO vSO) { string url = $"https://maps.googleapis.com/maps/api/geocode/json?address={vSO.VSOStreet},+{vSO.VSOCity},+{vSO.VSOState}&key={APIKeys.GeocodeKey}"; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(url); string jsonResult = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { JObject geoCode = JObject.Parse(jsonResult); vSO.Lat = (double)geoCode["results"][0]["geometry"]["location"]["lat"]; vSO.Long = (double)geoCode["results"][0]["geometry"]["location"]["lng"]; } if (ModelState.IsValid) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); vSO.IdentityUserId = userId; vSO.ImageLocation = null; _context.Add(vSO); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vSO)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,PhoneNumber,Email,ImageLocation,VSOStreet,VSOCity,VSOState,VSOZipCode,IdentityUserId")] VSO vSO) { if (id != vSO.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(vSO); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VSOExists(vSO.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", vSO.IdentityUserId); return(View(vSO)); }