public async Task <IActionResult> Edit(int id, [Bind("ViewerLocationId,ViewerLocationViewerId,ViewerLocationName,ViewerLocationAddress,ViewerLocationCity,ViewerLocationStateId,ViewerLocationZip,ViewerLocationLong,ViewerLocationLat,ViewerIsHomeLocation")] ViewerLocation viewerLocation)
        {
            if (id != viewerLocation.ViewerLocationId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Here is where we update the ViewerId
                    var    userId        = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                    Viewer currentviewer = _context.Viewers.Where(v => v.IdentityUserId == userId).FirstOrDefault();
                    viewerLocation.ViewerLocationViewerId = currentviewer.ViewerId;
                    string      state    = _context.State.Where(a => a.StateId == viewerLocation.ViewerLocationStateId).FirstOrDefault().StateAbbreviation.ToString();
                    string      address  = (viewerLocation.ViewerLocationAddress.ToString() + ", +" + viewerLocation.ViewerLocationCity.ToString() + ",+" + state);
                    GeoLocation location = await _geoCodeRequest.GetGeoLocation(address);

                    viewerLocation.ViewerLocationLat  = location.results[0].geometry.location.lat.ToString();
                    viewerLocation.ViewerLocationLong = location.results[0].geometry.location.lng.ToString();
                    viewerLocation.State = _context.State.Where(a => a.StateId == viewerLocation.ViewerLocationStateId).FirstOrDefault();
                    _context.Update(viewerLocation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ViewerLocationExists(viewerLocation.ViewerLocationId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ViewerLocationStateId"]  = new SelectList(_context.State, "StateId", "StateName", viewerLocation.ViewerLocationStateId);
            ViewData["ViewerLocationViewerId"] = new SelectList(_context.Viewers, "ViewerId", "ViewerId", viewerLocation.ViewerLocationViewerId);
            return(View(viewerLocation));
        }
        public async Task <IActionResult> Create([Bind("ViewerLocationId,ViewerLocationViewerId,ViewerLocationName,ViewerLocationAddress,ViewerLocationCity,ViewerLocationStateId,ViewerLocationZip,ViewerLocationLong,ViewerLocationLat,ViewerIsHomeLocation")] ViewerLocation viewerLocation)
        {
            if (ModelState.IsValid)
            {
                var    userId        = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                Viewer currentviewer = _context.Viewers.Where(v => v.IdentityUserId == userId).FirstOrDefault();
                viewerLocation.ViewerLocationViewerId = currentviewer.ViewerId;
                string      state    = _context.State.Where(a => a.StateId == viewerLocation.ViewerLocationStateId).FirstOrDefault().StateAbbreviation.ToString();
                string      address  = (viewerLocation.ViewerLocationAddress.ToString() + ", +" + viewerLocation.ViewerLocationCity.ToString() + ",+" + state);
                GeoLocation location = await _geoCodeRequest.GetGeoLocation(address);

                viewerLocation.ViewerLocationLat  = location.results[0].geometry.location.lat.ToString();
                viewerLocation.ViewerLocationLong = location.results[0].geometry.location.lng.ToString();
                viewerLocation.State = _context.State.Where(a => a.StateId == viewerLocation.ViewerLocationStateId).FirstOrDefault();
                _context.Add(viewerLocation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ViewerLocationStateId"] = new SelectList(_context.State, "StateId", "StateAbbreviation", viewerLocation.ViewerLocationStateId);
            return(View(viewerLocation));
        }