private static UserSyncResponseDto GetStatus(User user, List <Zone> zones) { string lat = user.Latitude.ToString().Replace(",", "."); string lng = user.Longitude.ToString().Replace(",", "."); const string url = "http://maps.frogfoot.net/ftth/check"; var syncResponse = new UserSyncResponseDto { ZoneAssigned = false, IsPossible = false, User = user }; if (!string.IsNullOrEmpty(lat) && !string.IsNullOrEmpty(lng)) { try { using (var client = new WebClient()) { string result = client.DownloadString(url + string.Format("?ll={0},{1}", lat, lng)); //if there is a zone that matches the zone code of the returned result the assign that zone to the user then save. dynamic data = JObject.Parse(result); string precinctCode = data["precinct-zone"]; if (data["possible"] == true && !string.IsNullOrEmpty(precinctCode)) { syncResponse.IsPossible = true; var zone = zones.FirstOrDefault(z => z.Code == precinctCode); if (zone != null) { user.ZoneId = zone.ZoneId; syncResponse.ZoneAssigned = true; syncResponse.ErrorMessage = result + " USER-ZONE-ID: " + user.ZoneId; } else { user.ZoneId = null; } } } } catch (Exception) { } } return(syncResponse); }
public static bool CheckUserZoneForISPOrdering(User user) { var repo = new GriddingRepository(); var zones = repo.GetZones().ToList(); var response = false; UserSyncResponseDto result = GetStatus(user, zones); if (result.User != null && result.User.ZoneId != null) { var zone = zones.FirstOrDefault(z => z.ZoneId == result.User.ZoneId); //if the map result == true and Zone == true or Location == true if (result.IsPossible && zone != null && zone.AllowOrder) { response = true; } } return(response); }