Ejemplo n.º 1
0
 public IActionResult EnterLocation([FromBody] UserLocationVM data)
 {
     try
     {
         if (data != null)
         {
             var user = _context.Users.Find(data.id);
             user.City  = data.city;
             user.State = data.state;
             string[] latLong = Geocoder.RunGeocoder(data.city, data.state);
             user.Latitude  = latLong[0];
             user.Longitude = latLong[1];
             _context.Users.Update(user);
             _context.SaveChanges();
             return(Ok());
         }
         else
         {
             return(NoContent());
         }
     }
     catch
     {
         throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
     }
 }
        private void GeocodeAddress(Customer customer, ApplicationDbContext db)
        {
            string address = customer.Address;
            string city    = customer.City;
            string state   = customer.State;

            string[] coordinates = Geocoder.RunGeocoder(address, city, state);
            customer.Latitude  = coordinates[0];
            customer.Longitude = coordinates[1];
            db.SaveChanges();
        }