/// <summary> /// Returns new or cached location guess based on client IP address /// </summary> /// <returns></returns> public LocationLookupResult PerformLocationGuess(bool includeCountryID) { LocationLookupResult locationGuess = null; if (Session["locationGuess"] != null) { locationGuess = (LocationLookupResult)Session["locationGuess"]; } if (locationGuess == null || (locationGuess != null && (locationGuess.Country_Code == null || includeCountryID && locationGuess.CountryID == 0))) { var clientIP = Request.ServerVariables["REMOTE_ADDR"]; locationGuess = GeocodingHelper.GetLocationFromIP_FreegeoIP(clientIP); if (includeCountryID) { var country = new ReferenceDataManager().GetCountryByISO(locationGuess.Country_Code); if (country != null) { locationGuess.CountryID = country.ID; } } Session["locationGuess"] = locationGuess; } return(locationGuess); }
public ActionResult SubscriptionEdit(int?id) { var subscription = new UserSubscription(); var userId = (int)UserID; if (id != null) { subscription = new UserSubscriptionManager().GetUserSubscription(userId, (int)id); } else { LocationLookupResult locationGuess = PerformLocationGuess(true); subscription.UserID = userId; subscription.NotificationFrequencyMins = 60 * 24 * 7;//default to 1 week subscription.DistanceKM = 100; if (locationGuess != null && locationGuess.Country_Code != null) { subscription.CountryID = locationGuess.CountryID; subscription.Country = new Country { ID = (int)locationGuess.CountryID, Title = locationGuess.Country_Name, ISOCode = locationGuess.Country_Code }; } else { //default to UK subscription.CountryID = 1; using (var refDataManager = new ReferenceDataManager()) { subscription.Country = refDataManager.GetCountryByISO("GB"); } } subscription.Latitude = null; subscription.Longitude = null; subscription.IsEnabled = true; subscription.NotifyComments = true; subscription.NotifyPOIAdditions = true; subscription.NotifyPOIUpdates = true; if (locationGuess != null && locationGuess.SuccessfulLookup) { if (locationGuess.CountryID != null) { subscription.CountryID = locationGuess.CountryID; } if (locationGuess.Latitude != null && locationGuess.Longitude != null) { subscription.Latitude = locationGuess.Latitude; subscription.Longitude = locationGuess.Longitude; } } subscription.Title = "Charging Locations Near Me"; } PopulateSubscriptionEditorViewBag(subscription); return(View("SubscriptionEdit", subscription)); }