/// <summary>
 /// Deprecated Method for adding a new object to the Locations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLocations(Location location)
 {
     base.AddObject("Locations", location);
 }
        private void SetGPSCoords(ref Location location)
        {
            using (var client = new System.Net.WebClient())
            {
                string addressString = location.StreetLine1.Replace(' ', '+') + ',' + location.Municipality.Replace(' ', '+') + ',' + location.State;
                string address = "https://maps.google.com/maps/api/geocode/json?address=" + addressString + "&sensor=false";
                string result = client.DownloadString(address);

                GoogleGeoCodeResponse response = new JavaScriptSerializer().Deserialize<GoogleGeoCodeResponse>(result);

                if (response.results.Count() > 0)
                {
                    location.Lattitude = response.results[0].geometry.location.lat;
                    location.Longitude = response.results[0].geometry.location.lng;
                }
            }
        }
 /// <summary>
 /// Create a new Location object.
 /// </summary>
 /// <param name="locationID">Initial value of the LocationID property.</param>
 /// <param name="businessID">Initial value of the BusinessID property.</param>
 /// <param name="visitorCount">Initial value of the VisitorCount property.</param>
 public static Location CreateLocation(global::System.Int32 locationID, global::System.Int32 businessID, global::System.Int32 visitorCount)
 {
     Location location = new Location();
     location.LocationID = locationID;
     location.BusinessID = businessID;
     location.VisitorCount = visitorCount;
     return location;
 }
        public void InsertLocation(int businessID, string street1, string street2, string municipality, string county, string state, string postalcode, string country, string phone)
        {
            using (var entities = new sunday_driveEntities())
            {
                Location newLocation = new Location()
                {
                    BusinessID = businessID,
                    StreetLine1 = street1,
                    StreetLine2 = street2,
                    Municipality = municipality,
                    County = county,
                    State = state,
                    PostalCode = postalcode,
                    Country = country,
                    Phone = phone
                };

                SetGPSCoords(ref newLocation);

                entities.Locations.AddObject(newLocation);

                entities.SaveChanges();
            }
        }